On this page
On this page
- What Is an ASG
- Instance Lifecycle States
- Lifecycle Hooks
- Wiring Lifecycle Hooks to Automation
- Method 1: EventBridge (Recommended)
- Method 2: SNS Notification Target (Legacy)
- Lambda Handler Pattern
- Launch Template vs. Launch Configuration
- Scaling Policies
- At a Glance
- Target Tracking (Recommended)
- Step Scaling
- Simple Scaling (Legacy)
- Scheduled Scaling
- Predictive Scaling
- Cooldown Period and Instance Warmup
- Health Checks
- EC2 Health Check (Default)
- ELB Health Check
- Health Check Grace Period
- Termination Policies
- Scale-In Protection
- Instance Refresh
- Warm Pools
- Mixed Instances Policy (Spot + On-Demand)
- Key CloudWatch Metrics
- Chaos Engineering โ AWS Fault Injection Service (FIS)
- Key Exam Scenarios
- CloudWatch Integration
- Automatically Published (AWS/AutoScaling namespace)
- Requires Setup
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.
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.
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.