Service Auto Scaling
Automatically adjust the desired count using Application Auto Scaling policies.
Service auto scaling changes the desired count in response to metrics, using AWS Application Auto Scaling.
Policy types
- Target tracking — keep a metric near a target, e.g. 60% average CPU.
- Step scaling — change count by steps as a CloudWatch alarm breaches.
- Scheduled — scale on a timetable for known traffic patterns.
Target tracking is the simplest and covers most needs.
Example
# Register the service as a scalable target, then track CPU at 60%
aws application-autoscaling register-scalable-target \
--service-namespace ecs --resource-id service/prod/web \
--scalable-dimension ecs:service:DesiredCount \
--min-capacity 2 --max-capacity 10
aws application-autoscaling put-scaling-policy \
--service-namespace ecs --resource-id service/prod/web \
--scalable-dimension ecs:service:DesiredCount \
--policy-name cpu60 --policy-type TargetTrackingScaling \
--target-tracking-scaling-policy-configuration 'TargetValue=60.0,PredefinedMetricSpecification={PredefinedMetricType=ECSServiceAverageCPUUtilization}'When to use it
- A team registers their ECS service with Application Auto Scaling and sets a target-tracking policy on CPU utilization to add tasks automatically during peak hours.
- An SRE adds a step scaling policy that adds 5 tasks when SQS queue depth exceeds 1000 messages so the processing service keeps pace with incoming work.
- A developer sets minimum capacity to 2 and maximum to 50 on the ECS service so auto-scaling never goes below the HA minimum or above the cost ceiling.
More examples
Register ECS Service as Scalable Target
Registers the ECS service as an Application Auto Scaling target with a minimum of 2 and maximum of 20 tasks.
aws application-autoscaling register-scalable-target \
--service-namespace ecs \
--resource-id service/prod/api \
--scalable-dimension ecs:service:DesiredCount \
--min-capacity 2 \
--max-capacity 20Create CPU Target-Tracking Policy
Creates a target-tracking policy targeting 60% average CPU utilization with a 60-second scale-out cooldown and 5-minute scale-in cooldown.
aws application-autoscaling put-scaling-policy \
--service-namespace ecs \
--resource-id service/prod/api \
--scalable-dimension ecs:service:DesiredCount \
--policy-name cpu-tracking \
--policy-type TargetTrackingScaling \
--target-tracking-scaling-policy-configuration \
'TargetValue=60.0,PredefinedMetricSpecification={PredefinedMetricType=ECSServiceAverageCPUUtilization},ScaleInCooldown=300,ScaleOutCooldown=60'Create SQS-Based Step Scaling Policy
Adds 2 tasks when queue depth is 0-1000 messages above the threshold and 5 tasks when it exceeds 1000, with a 2-minute cooldown between scale-outs.
aws application-autoscaling put-scaling-policy \
--service-namespace ecs \
--resource-id service/prod/worker \
--scalable-dimension ecs:service:DesiredCount \
--policy-name sqs-step \
--policy-type StepScaling \
--step-scaling-policy-configuration \
'AdjustmentType=ChangeInCapacity,StepAdjustments=[{MetricIntervalLowerBound=0,MetricIntervalUpperBound=1000,ScalingAdjustment=2},{MetricIntervalLowerBound=1000,ScalingAdjustment=5}],Cooldown=120'
Discussion