0Pricing
AWS Solutions Architect · Lesson

ECS Service Auto Scaling and Load Balancing

Attach an ALB to ECS services for path-based routing and configure service auto scaling to respond to CPU or custom CloudWatch metrics.

The Need for ECS Service Auto Scaling

A fixed desired count on an ECS service cannot respond to traffic fluctuations—you either over-provision (wasting money) or under-provision (degrading performance). ECS Service Auto Scaling automatically adjusts the desired count of tasks in response to CloudWatch metrics. It uses the Application Auto Scaling service under the hood—the same framework used by DynamoDB, Aurora, and ElastiCache. ECS service auto scaling supports target tracking, step scaling, and scheduled scaling policies.

Registering ECS as a Scalable Target

Before adding scaling policies, register the ECS service as a scalable target in Application Auto Scaling. Specify the minimum and maximum task counts, the cluster name, and the service name as the resource ID. This creates the boundary within which auto scaling will operate. The minimum count ensures you always have baseline capacity; the maximum prevents runaway scaling from exhausting Fargate capacity or EC2 instances.

aws application-autoscaling register-scalable-target \
  --service-namespace ecs \
  --scalable-dimension ecs:service:DesiredCount \
  --resource-id 'service/MyAppCluster/MyAppService' \
  --min-capacity 2 \
  --max-capacity 20

All lessons in this course

  1. ECS Clusters, Task Definitions, and Services
  2. EC2 Launch Type vs Fargate
  3. ECR: Storing and Pulling Container Images
  4. ECS Service Auto Scaling and Load Balancing
← Back to AWS Solutions Architect