What is Amazon EC2 Auto Scaling?
Amazon EC2 Auto Scaling helps you ensure that you have the correct number of Amazon EC2 instances available to handle the load for your application. It automatically adds instances (scale out) when demand increases and removes instances (scale in) when demand drops.
Key Concepts
1. Auto Scaling Group (ASG)
- A logical collection of EC2 instances.
- Minimum Capacity: The fewest number of instances the group should ever have.
- Maximum Capacity: The largest number of instances the group is allowed to have.
- Desired Capacity: The target number of instances the group currently attempts to maintain.
2. Launch Template
- A configuration file that specifies what to launch (AMI, Instance Type, Key Pair, Security Group).
- Note: Launch Configurations are legacy; Launch Templates are the modern standard.
3. Scaling Policies
- Target Tracking: "Keep CPU utilization at 50%". The easiest and most common method.
- Step / Simple Scaling: "If CPU > 70%, add 2 instances. If CPU < 30%, remove 1 instance."
- Scheduled Scaling: "Every Friday at 5 PM, scale up to 10 instances." (Predictable load).
- Predictive Scaling: Uses Machine Learning to predict future traffic and scale ahead of time.
Exam Tips
[!IMPORTANT] High Availability vs Scalability:
- Scalability: Adding more resources (ASG).
- High Availability: Surviving failures (ASG + ELB across multiple AZs).
- ASG helps with both.
[!NOTE] Self-Healing: If an instance becomes unhealthy (fails a health check), Auto Scaling will terminate it and launch a new one to replace it. This is a key "Self-Healing" pattern.
[!WARNING] Cooldown Period: A configurable time (default 300s) after a scaling activity during which ASG will not launch or terminate more instances. This prevents "thrashing" (rapidly scaling up and down).
Common Use Cases
- Web Servers: handling fluctuating traffic patterns.
- Batch Processing: Scaling up workers when a queue gets deep and scaling down when empty.
- Fault Tolerance: Keeping a minimum of 1 instance running at all times (Min=1, Max=1, Desired=1) ensures if it crashes, it automatically restarts.