Skip to content
BytePatterns

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.

  1. The group launches instances from the launch template
  2. Average CPU rises above the target value
  3. The load balancer routes to them once health checks pass
  4. The target tracking policy raises the desired capacity

Mini quiz

1 / 3

Application Load Balancer versus Network Load Balancer:

Sources

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.