Sub topic 14
Scaling policies: target tracking, step, scheduled and predictive
This chapter assumes you know what an Auto Scaling group (ASG) is, how its minimum, maximum and desired capacity work, and how CloudWatch metrics and alarms behave. A scaling policy is a rule that changes the desired capacity of the group. AWS never goes outside the min and max you set.
The four policy types
| Policy | Trigger | You provide | Best for |
|---|---|---|---|
| Target tracking | A metric drifts from a target | Metric and target value | Most workloads |
| Step scaling | A CloudWatch alarm you own | Alarm and size steps | Fine control over reactions |
| Scheduled | A date or recurring time | Time and capacity | Known, predictable events |
| Predictive | A forecast from past load | Metric and mode | Regular daily or weekly cycles |
Target tracking
Target tracking works like a thermostat. You pick a metric and a target value. The ASG creates and manages the CloudWatch alarms and adds or removes instances to keep the metric near the target. It scales out quickly and scales in more cautiously. Common predefined metrics are ASGAverageCPUUtilization and ALBRequestCountPerTarget.
Save this as config.json:
{
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ALBRequestCountPerTarget",
"ResourceLabel": "app/web-alb/50dc6c495c0c9188/targetgroup/web-tg/943f017f100becff"
},
"TargetValue": 1000.0
}Then attach it:
aws autoscaling put-scaling-policy \
--auto-scaling-group-name web-asg \
--policy-name requests-per-target-1000 \
--policy-type TargetTrackingScaling \
--target-tracking-configuration file://config.jsonDo not edit the alarms that target tracking creates. The service owns them and will overwrite your changes.
Step scaling
Step scaling reacts to an alarm that you create. The policy lists steps, and each step adds or removes a different amount depending on how far the metric is past the alarm threshold. For example, add 1 instance when CPU is 60–70%, and add 3 when it is above 70%. This gives you control, but you must choose the thresholds and keep the alarms correct.
Scheduled scaling
A scheduled action sets min, max or desired capacity at a given time. Recurrence uses cron syntax and is evaluated in UTC unless you set a time zone. Use it when you know about a launch, a sale or an office-hours pattern.
Predictive scaling
Predictive scaling forecasts load from the previous 14 days of metric history and launches capacity ahead of demand. It needs at least 24 hours of data and works best for cyclical traffic. Start in ForecastOnly mode, compare the forecast with real load, then switch to ForecastAndScale.
Combining policies
You can attach several policies to one group. If any policy asks for more capacity, the group scales out, and it uses the largest requested size. The group scales in only when all target tracking policies agree. A common setup is target tracking for reaction, scheduled actions for known peaks, and predictive scaling for daily cycles.
Exercise
Your traffic doubles every weekday at 09:00 and instances take 4 minutes to become useful. Target tracking alone reacts too late. Which policy would you add, and why?
Show answer
Add scheduled scaling (or predictive scaling if the pattern is regular and has 14 days of history). Both raise capacity before 09:00, so instances are already warm when traffic arrives. Keep target tracking in place to handle any load beyond the pattern.