> For the complete documentation index, see [llms.txt](https://karansingh.gitbook.io/tutorialsdojo-wrong-answers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://karansingh.gitbook.io/tutorialsdojo-wrong-answers/test-1-70/run-an-ecs-task-when-a-file-is-uploaded-to-an-s3-bucket-using-cloudwatch-events.md).

# 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**.<br>
* 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**.<br>
* You can also **declare a reduced number of ECS tasks whenever a file is deleted on the S3 bucket using the DELETE operation**.<br>
* First, you **must create a CloudWatch Events rule for the S3 service that will watch for object-level operations – PUT and DELETE objects**.<br>
* **For object-level operations, it is required to create a CloudTrail trail first**.<br>
* On the **Targets section, select the “ECS task”** and input the needed values such as the cluster name, task definition and the task count.<br>
* You **need two rules - one for the scale-up and another for the scale-down of the ECS task count**.
