AWSDOP-C02
On this page
Beginner-friendly overview

Auto Scaling

An Auto Scaling Group manages a fleet of EC2 instances as a single unit. It keeps a minimum number of instances running, can scale up when demand increases, and can scale back down when demand drops โ€” automatically, without manual intervention.

The Problem It Solves

Web traffic is rarely constant. A news site gets a surge at 9 AM. An e-commerce store gets slammed on Black Friday. A batch job runs at night and is idle during the day. Without auto scaling, you have two bad choices: over-provision (pay for servers you don't need most of the time) or under-provision (let the site go down when traffic spikes).

An ASG solves this by treating your compute capacity as elastic. You define the minimum and maximum number of instances you want, the conditions that should trigger scaling, and the ASG handles the rest.

Desired capacity floats between Min and Max โ€” the ASG keeps it healthy Max = 6 cost ceiling Min = 2 availability floor 2 AM โ€” quiet desired = 2 (at the floor) new new new 9 AM โ€” traffic spike desired = 5 (scaled out) โœ— failed โ†’ replaced 9:05 AM โ€” one fails terminated + relaunched, still 5 scale out self-heal You set Min / Max and the rules; the ASG moves Desired and replaces failures โ€” no human on the pager.

Launch Templates

Before an ASG can launch instances, it needs to know what kind to launch. A launch template captures all the configuration: AMI, instance type, security groups, IAM role, user-data script, and networking settings. The ASG uses this template every time it needs a new instance, ensuring all instances in the group are identical.

Scaling Policies

Target tracking โ€” the simplest and most common. You say "keep average CPU at 60%", and the ASG adds or removes instances to maintain that target. Works like a thermostat.

Step scaling โ€” trigger specific scaling actions at different alarm thresholds. Add 2 instances when CPU exceeds 70%, add 4 more when it exceeds 90%. More precise than target tracking for workloads with non-linear characteristics.

Scheduled scaling โ€” add capacity before you know you'll need it. Scale up to 50 instances at 7 AM every weekday; scale back down to 10 at 8 PM.

Predictive scaling โ€” uses machine learning to forecast future demand based on historical patterns and scales proactively before the traffic arrives.

The four scaling policies โ€” remember them as household objects:
Target tracking = thermostat (set "CPU 60%", it adjusts by itself) ยท Step scaling = staircase (bigger breach, bigger step) ยท Scheduled = calendar (you already know when the rush comes) ยท Predictive = crystal ball (ML forecasts the rush before it arrives)

Health Checks and Self-Healing

The ASG constantly checks whether instances are healthy. If an instance fails its EC2 health check (the instance is unresponsive), or fails the load balancer health check (the app on the instance returns errors), the ASG terminates it and launches a replacement. This self-healing behavior means your fleet automatically recovers from individual instance failures without any manual intervention.