ASG Basics
The goal: scale EC2 instances out to match load, scale in to save money, and always keep a minimum number running.
| Setting | Meaning |
|---|---|
| Min Size | The ASG will never go below this number. |
| Max Size | The ASG will never go above this number. |
| Desired Capacity | How many instances you want running right now. Changing it manually causes an immediate launch or terminate. |
Launch Template vs Launch Configuration
| Feature | Launch Template (recommended) | Launch Configuration (legacy) |
|---|---|---|
| Modifiable? | Yes — versioning supported | No — immutable, must recreate |
| Instance types | Mixed instances (Spot + On-Demand) | Single instance type only |
| Features | T2/T3 Unlimited, Dedicated Hosts | Limited feature set |
| Exam verdict | Always use this | Only under explicit legacy constraints |
Scaling Policies
The exam cares much more about which policy fits the scenario than about how to configure one.
Dynamic Scaling
Reactive scaling based on live metrics (CPU, network in/out, request count).
Target Tracking
- Concept: “Keep the average CPU at 50%.”
- How: You set a target value and the ASG creates the CloudWatch alarms for you. Above the target it adds instances, below it removes them.
- Keywords: “maintain average metric”, “easiest to set up”.
Step Scaling
- Concept: “Slightly high → add 1 instance. Very high → add 3.”
- How: You define steps based on how badly the alarm is breached.
- Key feature: Does not wait for the cooldown during scale out, so it reacts to spikes faster than Simple Scaling.
Simple Scaling (legacy)
- Concept: “Alarm breached → add 1 instance.”
- Downside: Must wait for the full cooldown period (default 300s) before scaling again. Step Scaling is preferred.
Predictive Scaling
Uses machine learning on historical data to forecast the next 48 hours and schedule scaling in advance.
Keywords: “recurring business patterns”, “scale proactively before the load hits”.
Scheduled Scaling
Scaling on a known clock — “every Friday at 5 PM traffic spikes”, “big marketing event Monday at 9 AM”.
Important ASG Mechanics
Scaling Cooldowns
A pause after a scaling activity (default 300 seconds) that lets metrics stabilize. During cooldown the ASG will not launch or terminate anything. Simple Scaling respects it; Step Scaling can override it for scale out.
If the ASG is thrashing (scaling up and down repeatedly), increase the cooldown.
Health Checks: EC2 vs ELB
| Check | What it verifies |
|---|---|
| EC2 status checks (default) | Only that the VM itself is running. Hardware failure → replace. |
| ELB health checks (optional) | The application health, via the load balancer. |
Important (Exam Tip)
The classic scenario: the instance is running (EC2 check passes) but the app is returning HTTP 500.
With ELB health checks enabled, the ASG terminates and replaces it.
With them disabled, the ASG keeps a broken app in rotation.
Termination Policy
When scaling in, the default policy picks the victim like this:
- Find the AZ with the most instances (keeps AZs balanced).
- Terminate the instance using the oldest launch template/configuration.
- Tie break on whichever is closest to the next billing hour.
You can enable Instance Scale-In Protection to shield specific instances — useful for long running jobs.
Advanced Features
Lifecycle Hooks
Pause an instance during creation or termination to run a custom action.
| Hook | When | Use Case |
|---|---|---|
Pending:Wait | Created but not yet serving traffic | Install software, download large datasets |
Terminating:Wait | About to be destroyed | Upload logs to S3, extract final data |
Typically wired to EventBridge or SNS → Lambda.
Instance Refresh
Updates every instance in the ASG to a new launch template (new AMI, new user data) with no downtime, using a rolling batch-by-batch replacement. Checkpoints let you say “replace 20%, then wait an hour” to verify stability.
Warm Pools
- Problem: Instances take 5+ minutes to boot and install software, making dynamic scaling too slow to matter.
- Solution: A pool of pre-initialized instances kept in a
Stoppedstate. - Benefit: Scaling out starts a stopped instance instead of building a new one — dramatically faster.
Scenario Cheat Sheet
| Scenario | Solution |
|---|---|
| Traffic is unpredictable and spiky | Target Tracking on a CPU or network metric |
| Traffic has a known weekly pattern | Scheduled Scaling |
| Need to scale before the load hits, based on history | Predictive Scaling |
| Prevent one specific instance from being terminated | Scale-In Protection |
| App takes 10 minutes to install on boot | Warm Pools, or bake a Golden AMI |
| Run a script before an instance terminates | Lifecycle Hook (Terminating:Wait) |
| Patch the OS across all ASG instances | Instance Refresh (rolling update) |
| Availability Zones are unbalanced | ASG rebalances automatically — launches in one AZ, terminates in another |