Multiple Tasks Definition on ECS Service using CloudFormation

6.9k Views Asked by At

Hi I'm newbie on CloudFormation AWS, and I'm working right now with a ECS Service with 1 task, but I would like to put more tasks using CloudFormation. However inside the properties on AWS ECS Service, there's one called Task Definition, and only allows to put 1 tasks. How can I configure in order to use more tasks. I´m doing the project on the same Region. Thanks

Task Definition Property

3

There are 3 best solutions below

0
On BEST ANSWER

I've already got it. There's other parameter called DesiredCount, and it's gonna make x replicas, depending the number of tasks you need. So if you want to put 5 tasks in your service, DesiredCount parameter that you have to put is 5. Here is the link if you want to search the parameter DesiredCount for more info.

0
On

Sadly, you can't do this. A single service can run multiple copies of only one task. So if you want to run multiple instances of different tasks in multiple, you have to create multiple services, i.e., one service per task.

However, a single task can contain multiple containers.

0
On

Fundamentally, an ECS Service is supposed to run just one "kind" of service - just one microservice, if you will. The container image for that microservice is defined in the task definition.

So think of an ECS Service like running instance(s) of a microservice. It can run multiple instances(tasks) of the same microservice(task definition) if that microservice needs to be scaled up, by specifying DesiredCount property.

From ECS best practices guide -

Use each task definition family for only one business purpose

You can use an Amazon ECS task definition to specify multiple containers. All the containers that you specify are deployed along the same compute capacity. Don't use this feature to add multiple application containers to the same task definition because this prevents copies of each application scaling separately.

Later in the same section -

The purpose of having multiple containers in a single task definition is so that you can deploy sidecars, small addon containers that enhance a single type of container. A sidecar might help with logging and observability, traffic routing, or other addon features.