Deployed Fargate Task when object uploaded to S3


I have a scenario where I need to deploy a Fargate task when an object is uploaded to an S3 bucket. I know that I can introduce a Lambda function in between to deploy the task, but is it possible to use EventBridge to deploy the task without a queue or Lambda function?

asked 3 months ago131 views
2 Answers
Accepted Answer

You can use EventBridge to deploy an ECS task. However, even if the ECS task is deployed, the container will not receive the event details such as the S3 bucket name and key by default. One solution is to configure the target input in EventBridge rule to override the environment variables of the container. This way, the container can perform the job based on the S3 bucket name and key.

Follow these steps (assuming that S3 is the source event):

  1. In the EventBridge, select ECS as the target.
  2. Update the 'Configure target input' to 'Input Transformer' and configure the input transformer.
  3. Update the 'Target input transformer' to define the variables and assign each value based on the event before EventBridge passes it to the target. Example: {"bucketname":"$","keyname":"$.detail.object.key"}
  4. Update the 'Input Template' to pass the information to the target. In this step, pass the variables defined in Step 3 and override the environment variables of the container using the containerOverride command. In Step 3, we defined bucketname as the variable name and passes the bucket name from the event. To use the variable, define <bucketname> to use the value. {"containerOverrides": [{"name":"containerName","environment":[{"name":"BUCKETNAME","value":"<bucketname>"},{ "name":"S3_KEY","value":"<keyname>" }]}]} Note: the name is the container name that you assign in the task definition.
  5. Your container will be able to access the environment variables 'BUCKETNAME' and 'S3_KEY'.
answered 3 months ago


It should probably be possible since you can select ECS Task as the target of EventBridge.

From the management console, you can select ECS Task when creating an EventBridge rule as shown below, so you can probably start it.

profile picture
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions