15 - Containers on AWS ECS Fargate ECR EKS

Amazon ECS - Auto Scaling

awscontainersecsauto-scalingsaa-c03

Overview

You can manually increase the number of ECS tasks in a service, or automatically increase and decrease them with AWS Application Auto Scaling.

Metrics to Scale On

Only these three metrics need to be remembered:

Metric Details
ECS Service CPU Utilization CPU of the service
ECS Service Memory Utilization RAM of the service
ALB Request Count Per Target Metric coming from the ALB

Scaling Types

  • Target Tracking - track a specific target value for one of the three metrics
  • Step Scaling
  • Scheduled Scaling - scale ahead of time for predictable changes
Task Level vs Cluster Level

Scaling the ECS service at the task level is not the same as scaling the cluster of EC2 instances in the EC2 launch type. With Fargate, no EC2 auto scaling is needed because everything is serverless, so service auto scaling is much easier. The exam pushes Fargate a lot.


Scaling EC2 Instances (EC2 Launch Type)

Option Details
Auto Scaling Group scaling Scale the ASG, e.g. on CPU Utilization, adding EC2 instances over time if CPU rises
ECS Cluster Capacity Provider Newer, more advanced. Paired with an ASG; when you lack capacity (RAM or CPU) to launch new tasks, it automatically scales the ASG and EC2 instances are created
Exam Pattern

Choosing between ASG scaling and Capacity Provider for the EC2 launch type: use ECS Cluster Capacity Provider (the smarter way). See ASG.


Scaling Flow Example

  1. Service A has 2 tasks, autoscaled by Application Auto Scaling.
  2. More users arrive and CPU usage goes up.
  3. The CloudWatch Metric for ECS service CPU triggers a CloudWatch Alarm.
  4. The alarm triggers a scaling activity; the desired capacity of the ECS service increases and a new task is created.
  5. Optionally, on the EC2 launch type, ECS Capacity Providers scale the EC2-backed cluster.

ECS service scaling flow

ECS serviceCPU usage goes up CloudWatch metricECS service CPU CloudWatch Alarmscaling activity Desired capacitynew task created Capacity ProviderEC2 launch type only Application Auto Scaling handles the task count. Fargate needs no EC2 scaling.
A CloudWatch alarm drives Application Auto Scaling to raise the desired capacity.

Questions & Answers

Q1: Which service auto scales ECS tasks?

Answer:

AWS Application Auto Scaling.

Q2: Which three metrics can ECS service scaling use?

Answer:

CPU Utilization, Memory Utilization and ALB Request Count Per Target.

Q3: Best way to scale EC2 instances behind ECS?

Answer:

The ECS Cluster Capacity Provider paired with an ASG, rather than plain ASG scaling.

Q4: Why is Fargate easier to scale?

Answer:

There are no EC2 instances behind it, so only the task count needs scaling.

Check yourself

Quiz

Flashcards

Click the card (or focus it), then use ← → to move and Space to flip.