How to run AWS ECS Task with CloudFormation overriding container environment variables


I was searching a way to run ecs task. I already have a cluster and task definition settings. I just wanted to trigger a task using CloudFormation template. I know that I can run a task by clicking on the console and it works fine. For cfn, approach needs to be define properly.

Check the attached screenshots. I wanted to run that task using CloudFormation and pass container override environment variables. As per my current templates, it is not allowing me to do same like I can do using console. Using console I just need to select the following options

It starts working with console but with cloudformaton template how can we do that. Is it possible to do or there is no such feature?

enter image description here

ECS Run Task by using aws console

There is no validity error in the code however, I am talking about the approach. I added image name container name but now it is asking for memory and cpu, it should not ask as it is already defined we just need to run a task.


I wanted to run a task after creation of my database and wanted to pass those database values to the task to run and complete a job.

enter image description here


Here is the working example of what you can do if you wanted to pass variable and run a task. In my case, I wanted to run a task after creation of my database but with environment variables, directly AWS does not provide any feature to do so, this is the solution which can help to trigger you ecs task.

Leave a Reply