Search code examples
amazon-ec2amazon-ecsaws-auto-scaling

Difference between Auto Scaling Group, ECS Capacity Provider and ECS Service Auto Scaling


I'm having trouble understanding the differences between the properties for the Auto Scaling Group, ECS Capacity Provider and Service Auto Scaling. I'm using terraform to create the infrastructure and also to deploy the services.

I have an API in one ECS Service that basically handles all requests, but I created 2 just in case. The task definition is set to use 512 cpu and 1024 memory.

In the possibility that my API could scale up, I need to be able to scale in and out the containers or EC2 instances.

So basically I need:

  • 1 Auto Scaling Group
  • 1 ECS Capacity Provider (linked to the ASG)
  • 1 ECS Service Auto Scaling (to scale when it reaches 70% cpu for example)

My question are:

  • What is the min and max size of the ASG? The number of EC2 instances that can scale in and out?
  • What is the minimum and maximum scaling step size of the ECS Capacity Providers? If I set the maximum to 10, it means that it can scale out 10 EC2 instances at the same time? Do I need to set this?
  • What is the min and max capacity of the ECS Service Auto Scaling? The number of ECS services that can deploy based on the target tracking?

With a small example

  • If I use t3.small instances (2 GiB memory)
  • ASG to min=1, max=2
  • ECS Capicity provider min=max=1
  • ECS Service min=1, max=5

From my understanding, if the API reaches 70% cpu, scales to 2 services (still only needs one EC2 instance). The next scale outs imply a new EC2 instance. The 5th will not work. Is this correct?


Solution

  • What is the min and max size of the ASG? The number of EC2 instances that can scale in and out?

    Yes that's correct

    What is the minimum and maximum scaling step size of the ECS Capacity Providers? If I set the maximum to 10, it means that it can scale out 10 EC2 instances at the same time? Do I need to set this?

    That is part of the ECS Managed Scaling settings for the ECS capacity provider. If you have ECS managed scaling enabled, then these settings basically override the settings in the ASG, and allow ECS to have direct control over the scaling of the EC2 instances. This basically allows ECS to set the "desired count" setting in the ASG directly. In most cases you would want Managed Scaling enabled, so you will need to set these values.

    In your example configuration, you definitely want those values set to 1.

    What is the min and max capacity of the ECS Service Auto Scaling? The number of ECS services that can deploy based on the target tracking?

    It's the number of ECS tasks for that service that can be deployed.

    From my understanding, if the API reaches 70% cpu, scales to 2 services (still only needs one EC2 instance). The next scale outs imply a new EC2 instance. The 5th will not work. Is this correct?

    That looks correct to me.


    I would point out that if you switched to using Fargate instead of EC2, the ASG and Capacity Provider would just go away, and you would have a much simpler configuration. And you would only be paying for the resources needed for the containers/tasks that are running, instead of paying for an EC2 instance that can support 2 of your tasks when only 1 task is running.