Scaling policies
How Auto Scaling groups decide to scale, with CloudWatch alarms, target tracking, step, scheduled and predictive policies, good metrics, cooldowns, warm pools, instance refresh, and AWS Auto Scaling.
What it is
A scaling policy tells an Auto Scaling group when to change its desired capacity. Most policies watch a CloudWatch metric and react to it; others follow a schedule or a forecast.
Scaling on CloudWatch alarms
- A CloudWatch metric, such as the average CPU across the group's instances or a custom metric, is collected.
- A CloudWatch alarm goes off when the metric crosses a threshold, for example CPU above 70% for 5 minutes.
- The alarm triggers a scaling policy: scale out (add instances) or scale in (remove them).
- The group launches or terminates instances, and registers them with the load balancer.
The policy types
Dynamic scaling
- Target tracking (recommended): pick a metric and a target value, for example "keep the group's average CPU around 40%". Auto Scaling creates and manages the alarms, scaling out and in to stay near the target. The simplest to set up.
- Step scaling: create the CloudWatch alarms and set how much to change at each level, for example "CPU above 70%: add 2 instances; above 90%: add 4; below 30%: remove 1".
- Simple scaling: one alarm, one change, then wait for the cooldown. Older; AWS recommends target tracking or step scaling instead.
Scheduled scaling
Change capacity at known times, based on usage patterns already known. For example: "set the minimum to 10 at 17:00 every Friday" before the weekend rush, and back to 2 on Monday.
Predictive scaling
Auto Scaling analyses the history of the load, finds daily and weekly patterns, forecasts the coming load and schedules capacity ahead of it. It's best for regular, cyclical traffic and apps that take a while to start, because instances are ready before the peak arrives. It works alongside dynamic scaling.
Good metrics to scale on
- CPUUtilization: average CPU across the instances. The common default.
- RequestCountPerTarget (
ALBRequestCountPerTarget): requests per instance from the ALB, for example "keep about 1,000 requests per target". Good for web apps, because it tracks real demand. - Average NetworkIn / NetworkOut: for apps limited by network.
- Any custom metric published to CloudWatch, such as queue length (see SQS with Auto Scaling) or active sessions.
Cooldowns and warmup
- After a scaling activity, a group using simple scaling waits for a cooldown (300 seconds by default) before scaling again, so metrics can settle and it doesn't overreact.
- Target tracking and step policies instead use an instance warmup: new instances don't count toward the metric until they've had time to start. AWS recommends setting a default instance warmup for the group.
- Tip: use a ready-to-go (golden) AMI, so instances start serving sooner and cooldowns or warmups can be shorter.
Warm pools
Some apps take a long time to boot, for example because they load gigabytes of data first. A warm pool keeps pre-initialised instances next to the group.
- Instances in the pool can be kept stopped (billed only for EBS), hibernated (memory kept), or running.
- On scale-out the group takes instances from the pool, which start serving much faster than brand-new ones.
- By default the pool size is the group's maximum minus its desired capacity.
- Don't add one if boot time isn't a problem: it costs money for nothing.
Instance refresh
An instance refresh replaces the instances in a group in a rolling way, for example after a new launch template version is created with a new AMI or instance type.
- Instances are replaced in batches while a minimum healthy percentage (90% by default) keeps serving traffic.
- Checkpoints can be added to pause and check, skip instances that already match, and roll back automatically if the new version is unhealthy.
- This gives immutable deployments: instead of patching servers in place, they're replaced with new ones built from the new image.
Not in the course slides
Warm pools and instance refresh are in the exam guide but not in the course slides. These sections are written from the AWS documentation.
AWS Auto Scaling and Application Auto Scaling
Three AWS services have "Auto Scaling" in their name, and the exam guide lists two of them by name. They fit together like this:
- Amazon EC2 Auto Scaling is everything on this page and the Auto Scaling groups page: it adds and removes EC2 instances in Auto Scaling groups.
- Application Auto Scaling scales other AWS services with the same kinds of policy (target tracking, step and scheduled scaling): the task count of ECS services, the read and write capacity of DynamoDB tables, the number of Aurora replicas, Lambda provisioned concurrency, ElastiCache clusters, Spot Fleets and more. It's usually set up from each service's own console, for example "Aurora replica auto scaling" in the RDS console.
- AWS Auto Scaling is a single console for scaling plans. A scaling plan sets up scaling for several related resources at once: EC2 Auto Scaling groups, ECS services, DynamoDB tables and indexes, Aurora replicas and Spot Fleets.
- It discovers the scalable resources of an application, found by tags or by CloudFormation stack.
- It offers scaling strategies with recommendations: optimize for availability, for cost, or a balance of both.
- It sets up dynamic scaling (target tracking) through EC2 Auto Scaling and Application Auto Scaling, and can add predictive scaling for Auto Scaling groups.
For example, a web app tagged app=shop has an Auto Scaling group, an ECS service and a DynamoDB table. One scaling plan keeps the instances near 50% CPU, the ECS tasks near 60% CPU and the table near 70% capacity use, instead of three separate setups.
Not in the course slides
The course slides don't cover AWS Auto Scaling as a separate service, but it is on the exam guide's in-scope list. This section is written from the AWS documentation.
Other features worth knowing
- Lifecycle hooks pause an instance while it launches (
Pending:Wait) or terminates (Terminating:Wait), one hour by default, so a script can install software or copy logs first. - Termination policy: on scale-in, the group first keeps the AZs balanced, then by default removes instances with the oldest launch template or configuration.
- Capacity rebalancing replaces Spot Instances that get a rebalance recommendation before they're interrupted.
Exam tips
- "Keep average CPU at 50%", "simplest way to scale on a metric" → target tracking.
- "Scale every Friday at 5 pm", "known event" → scheduled scaling.
- "Daily or weekly cyclical traffic, scale ahead of demand" → predictive scaling.
- "Scale by number of requests per instance" → target tracking on
ALBRequestCountPerTarget. - "Instances take a long time to boot, so scale-out is too slow" → warm pool (and a golden AMI).
- "Roll out a new AMI to all instances in the group with no downtime" → new launch template version + instance refresh.
- "Run a script before an instance is terminated" → lifecycle hook.
- "Group scales out again too soon" → cooldown (simple scaling) or instance warmup.
- "Set up scaling for EC2, ECS, DynamoDB and Aurora of one application from a single place", "scaling plan" → AWS Auto Scaling.
- "Scale DynamoDB capacity, ECS tasks or Aurora replicas automatically" → Application Auto Scaling (through each service's auto scaling settings).
Common traps
- "Scale on the CPU of one instance." Use the group-wide average (or a per-target metric).
- "Use simple scaling for new designs." Target tracking or step scaling is recommended.
- "Instance refresh changes the launch template." The template is changed first; the refresh replaces the instances.
- "AWS Auto Scaling and EC2 Auto Scaling are the same service." EC2 Auto Scaling scales instances; AWS Auto Scaling creates scaling plans across several services.
Hands-on lab: scale on CPU with target tracking
Goal: add a target tracking policy and watch the group scale out when you load the CPU, then back in.
Costs money
Uses saa-asg from the Auto Scaling groups lab, plus up to two more t3.micro instances for a few minutes: well under $0.20 for the lab. Burstable instances running at 100% CPU may add a few cents of CPU credit charges.
Add the policy
Open saa-asg → Automatic scaling → Create dynamic scaling policy: type Target tracking scaling, metric Average CPU utilization, target value 40, instance warmup 60 seconds. Create.
Load the CPU
Connect to one of the group's instances with EC2 Instance Connect and run a busy loop on both vCPUs:
yes > /dev/null & yes > /dev/null &Watch it scale out
In a few minutes, CloudWatch sees the group's average CPU above 40%. The Activity tab shows new instances launching, and the desired capacity rises (up to the maximum of 4). In CloudWatch → Alarms you can see the two alarms target tracking created for you.
Stop the load
Run pkill yes on the instance. Over the next 15 minutes or so, the group scales back in to the minimum of 2 (scale-in is deliberately slower than scale-out).
Expected result: the group adds instances under load and removes them when the load is gone, without you touching the desired capacity.
Clean up: delete the Auto Scaling group saa-asg (it terminates its instances), then the load balancer, the target group saa-asg-tg, and the launch template saa-lt. Target tracking deletes its own alarms with the policy.