Run an ECS Task When a File is Uploaded to an S3 Bucket using CloudWatch Events

  • You can use CloudWatch Events to run ECS tasks when certain AWS events occur.

  • You can set up a CloudWatch Events rule that runs an ECS task whenever a file is uploaded to a certain S3 bucket using the S3 PUT operation.

  • You can also declare a reduced number of ECS tasks whenever a file is deleted on the S3 bucket using the DELETE operation.

  • First, you must create a CloudWatch Events rule for the S3 service that will watch for object-level operations – PUT and DELETE objects.

  • For object-level operations, it is required to create a CloudTrail trail first.

  • On the Targets section, select the “ECS task” and input the needed values such as the cluster name, task definition and the task count.

  • You need two rules - one for the scale-up and another for the scale-down of the ECS task count.

Last updated

Was this helpful?