Lab 4 · EC2 Auto Scaling + ELB¶
Resilient · Est. time: 40–50 min ·
Cost: ⚠️ the Application Load Balancer is NOT Free Tier (bills hourly + per LCU); t2.micro/
t3.micro instances are Free-Tier eligible. Tear everything down at the end.
Goal. Build the exam's canonical resilient web tier — ALB → Auto Scaling group across 2 AZs — and watch it self-heal when you kill an instance (Topic 4).
Prereq
Use the lab-vpc from Lab 1, or the default VPC. You need two subnets in
different AZs.
Step 1 — Launch template¶
- EC2 → Launch templates → Create launch template. Name
lab-lt. - AMI: Amazon Linux 2023. Instance type: t2.micro/t3.micro (Free Tier).
- User data (installs a web page that shows the instance ID):
- Security group: allow HTTP 80 from anywhere (lab only). Create the template.
Step 2 — Application Load Balancer + target group¶
- EC2 → Load Balancers → Create → Application Load Balancer. Name
lab-alb, internet-facing. - Select two subnets in different AZs.
- Security group: allow HTTP 80.
- Create a target group
lab-tg(type Instances, protocol HTTP:80, health check path/). - Finish creating the ALB pointing at
lab-tg.
Billing starts now
The ALB bills from creation. Note the time; delete it in teardown.
Step 3 — Auto Scaling group across 2 AZs¶
- EC2 → Auto Scaling groups → Create. Name
lab-asg, launch templatelab-lt. - Select the two AZs/subnets.
- Attach to an existing load balancer → target group
lab-tg. - Health check type: ELB (not just EC2 — the Topic 4 gotcha). Health check grace ~90s.
- Desired 2, Min 2, Max 4. Create.
aws autoscaling create-auto-scaling-group --auto-scaling-group-name lab-asg \
--launch-template LaunchTemplateName=lab-lt --min-size 2 --max-size 4 --desired-capacity 2 \
--vpc-zone-identifier "subnet-aaa,subnet-bbb" \
--target-group-arns <lab-tg-arn> --health-check-type ELB --health-check-grace-period 90
Step 4 — Test resilience and scaling¶
- Browse to the ALB DNS name (EC2 → Load Balancers →
lab-alb→ DNS name). Refresh — you'll see responses from different instance IDs across AZs (load balancing). - Kill an instance: EC2 → Instances → terminate one. Watch the ASG detect the failure (ELB health check) and launch a replacement to return to desired = 2. That's self-healing.
- (Optional) Add a target-tracking policy (keep average CPU at 50%) to see scaling config — generating real CPU load is optional.
Teardown¶
- Delete the Auto Scaling group
lab-asg(this terminates its instances). - Delete the ALB
lab-alb— stops the hourly bill. - Delete the target group
lab-tgand the launch templatelab-lt. - Delete the lab security groups if unused.
✅ What you should understand now¶
- ALB + ASG across ≥ 2 AZs is the resilient web-tier default — survives an AZ failure and self-heals failed instances.
- Setting the ASG health check type to ELB (not the default EC2) is what makes it replace instances the load balancer considers unhealthy.
- The ALB spreads traffic across healthy targets in multiple AZs (you saw different instance IDs).
- An ALB is not Free Tier — always delete it after labs.
- Target tracking is the go-to scaling policy; scheduled/predictive are for known/forecastable patterns.
Related: Learn — HA & Fault Tolerance