amazon-web-servicesamazon-ecsaws-ecs

How to scale tasks / containers in AWS ECS


This is an introductory guide by AWS on how to deploy microservices - based applications on ECS

Apparently (as also becomes evident from the documentation), a so called task definition should encompass all of your containers that make up you stack.

i.e. if your corresponding docker-compose.yml file was made of 5 services (in the docker compose context), these should all end up in the same ECS Task Definition (?).

From what I understand, this also serves the purpose of automated service discovery among the containers (as is the default behavior in docker-compose and docker swarm);

The problem lies in the fact that the scaling possibility when it comes to ECS is (besides EC2 instance) per ECS Service.

Does this mean that you cannot have container-level scaling ?

If I want a service scale, I would have to scale all of my containers within my so called stack?


Solution

  • You do not need to have all containers in the same task definition. From the docs:

    Your entire application stack does not need to exist on a single task definition, and in most cases it should not. Your application can span multiple task definitions by combining related containers into their own task definitions, each representing a single component.

    Also, note that you are limited to 10 container definitions in a single task definition and it's perfectly fine to use just one container definition in each of your task definitions.

    As for scaling, you can create a service for each task definition. This allows logically separate components in your stack to scale independently. For example, if you have 2 services, one for back-end api service and another for front-end nginx, you can create 2 separate task definitions for them, each service scaling independently.

    Possible reasons to group your container definitions into a single task definition:

    On the other hand, if the containers perform separate logical functions, scale independently, don't share a lifecycle or resources like volumes, you are probably better off using multiple task definitions/services.

    There is also some documentation on application architecture for ECS here which explains this further.