EC2, Auto Scaling & Load Balancers
AWS for Interviews: lesson 3 of 18
A fleet that grows with traffic and heals itself, behind one address.
Lesson 3 of 18 · 6 min
EC2, Auto Scaling & Load Balancers
Step 1 of 11
Two instances in two Availability Zones behind a load balancer. The group says: min 2, max 4.
The Idea
An Auto Scaling group keeps EC2 instances between a minimum and a maximum, launched from a launch template and spread across Availability Zones. A target tracking policy holds a metric — say average CPU at 50% — by adding or removing instances. The load balancer only sends traffic to healthy targets, and the group replaces instances that fail health checks.
Real-World Example
A ticketing site idles on two instances until an on-sale starts. CPU passes the target, the group launches two more in two zones, the Application Load Balancer routes to them once their health checks pass, and at night the group scales back toward its minimum.
The Tradeoff
New instances take time to boot and warm up, so scaling reacts in minutes, not seconds. For spikes you can see coming, add scheduled or predictive scaling. ALB routes HTTP by path and host; NLB handles TCP and UDP at layer 4.
Hands-On
# illustrative — needs an AWS account and an existing group named web-asg
aws autoscaling put-scaling-policy \
--auto-scaling-group-name web-asg \
--policy-name cpu50 \
--policy-type TargetTrackingScaling \
--target-tracking-configuration \
'{"PredefinedMetricSpecification": {"PredefinedMetricType": "ASGAverageCPUUtilization"}, "TargetValue": 50.0}'
Your turn
Put the steps in the right order.
- The group launches instances from the launch template
- Average CPU rises above the target value
- The load balancer routes to them once health checks pass
- The target tracking policy raises the desired capacity
Mini quiz
1 / 3
Application Load Balancer versus Network Load Balancer:
Sources
- Auto Scaling groups — Amazon EC2 Auto Scaling User Guide
- Target tracking scaling policies — Amazon EC2 Auto Scaling User Guide
- Health checks for instances in an Auto Scaling group — Amazon EC2 Auto Scaling User Guide
- What is an Application Load Balancer? — Elastic Load Balancing