cloudwithshad
GUIDED LAB · ~90 MINUTES

Build an auto-scaling app with ALB

Build a load-balanced app that automatically scales from 2 → 6 servers when CPU spikes, then scales back down when traffic dies. The exact pattern Netflix and Spotify use every night.

7
STEPS
90 min
DURATION
~$1
EST. COST
ALB + ASG
SERVICES
1
The plan — what we're building
5 min

Here's the architecture. Plan it on paper first — same discipline as Week 2.

Users Application Load Balancer DNS: cloudwithshad-alb-xxx.elb.amazonaws.com Auto Scaling Group · min:2 · desired:2 · max:6 EC2 #1 af-south-1a healthy ✓ EC2 #2 af-south-1b healthy ✓ EC2 #3 launches if CPU > 50% 📊 CloudWatch
2 EC2s always running. ASG spins up more when CPU > 50%. ALB balances traffic across all of them.
ComponentConfiguration
VPCUse your default VPC (saves time — we focused on custom VPCs in Week 2)
Subnets2 public subnets in 2 different AZs (high availability)
EC2 typet2.micro or t3.micro (free tier)
ASG min / desired / max2 / 2 / 6
Scaling triggerTarget tracking: CPU > 50%
Heads up on cost

An ALB costs ~$0.50/day even with zero traffic. It's small, but it's not free. Delete the ALB the moment you finish this lab — don't leave it running overnight.

2
Create the Launch Template
15 min

A Launch Template is a blueprint for an EC2 instance. The Auto Scaling Group will use it whenever it needs to spin up a new server.

Navigate to EC2 → Launch Templates → Create launch template.

aws EC2 → Launch Templates → Create
Launch template name
cloudwithshad-web-template
AMI
Amazon Linux 2023 (free tier eligible)
Instance type
t2.micro
Key pair
Use existing (from Week 1)
Security group
Create new: web-sg (allow port 80 from 0.0.0.0/0)
User data (Advanced details)
See script below

The user data script makes each new EC2 instance auto-install nginx, show its own instance ID (so we can see load balancing in action), and install stress (a tool to artificially spike CPU later):

#!/bin/bash yum update -y yum install -y nginx stress # Get IMDSv2 token TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") # Get this instance's metadata so we can display it INSTANCE_ID=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id) AZ=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/availability-zone) # Build a unique page so we can see which server is responding cat > /usr/share/nginx/html/index.html <<EOF <html><head><title>cloudwithshad ASG</title></head> <body style="font-family: sans-serif; background:#0A1628; color:#fff; text-align:center; padding:50px;"> <h1>☁️ cloudwithshad Auto-Scaling Demo</h1> <h2 style="color:#00B4D8;">Instance: $INSTANCE_ID</h2> <p>AZ: $AZ</p> <p style="opacity:0.7;">Refresh the page — you should see different instance IDs!</p> </body></html> EOF systemctl start nginx systemctl enable nginx

Click Create launch template.

Exam tip

Launch Templates replaced "Launch Configurations" (the older, deprecated way). On the exam, both might appear — but in real life and the console UI, always use Launch Templates.

3
Create the Target Group
10 min

The Target Group is the list of EC2 instances the ALB sends traffic to. Think of it as the "team roster".

Navigate to EC2 → Target Groups → Create target group.

FieldValue
Target typeInstances
Target group namecloudwithshad-tg
Protocol / PortHTTP / 80
VPCYour default VPC
Protocol versionHTTP1
Health check path/
Health check interval30 seconds
Healthy threshold2 consecutive successes

Click Next, then Create target group (don't add any instances yet — the ASG will do that).

What "healthy threshold" means

The ALB will ping / on each instance every 30 seconds. It only marks the instance as healthy after 2 consecutive successful pings. This prevents accidentally serving traffic to a still-booting server.

4
Create the Application Load Balancer
15 min

Now the star of the show. Navigate to EC2 → Load Balancers → Create load balancer.

  1. Select Application Load Balancer → Create
  2. Name: cloudwithshad-alb
  3. Scheme: Internet-facing
  4. IP address type: IPv4
  5. VPC: your default VPC
  6. Mappings: tick at least 2 AZs and select the public subnets in each
  7. Security group: create new → alb-sg with port 80 open to 0.0.0.0/0
  8. Listeners and routing: HTTP/80 → forward to cloudwithshad-tg
  9. Click Create load balancer

ALB takes about 2-3 minutes to provision. While you wait:

Why 2 AZs is required

ALBs require subnets in at least 2 AZs. This is the same Multi-AZ requirement you saw with RDS in Week 2 — it's how AWS enforces high availability. Even if one AZ has an outage, your ALB keeps routing through the other.

Once the state shows "Active", copy the DNS name (looks like cloudwithshad-alb-1234567890.eu-west-1.elb.amazonaws.com). Save it — we'll need it after Step 5.

5
Create the Auto Scaling Group
15 min

This is the magic. Navigate to EC2 → Auto Scaling Groups → Create Auto Scaling Group.

SettingValue
Namecloudwithshad-asg
Launch templatecloudwithshad-web-template (from Step 2)
VPCDefault VPC
Availability ZonesPick at least 2 (same as your ALB)
Load balancingAttach to existing load balancer
Target groupscloudwithshad-tg
Health checksEnable ELB health checks
Desired capacity2
Min capacity2
Max capacity6
Scaling policiesTarget tracking
MetricAverage CPU utilization
Target value50

Click Create Auto Scaling group.

Within 2 minutes, the ASG launches 2 EC2 instances automatically and registers them with your Target Group. Once they pass health checks (about 60 seconds), open the ALB's DNS name in your browser. Refresh the page a few times — you should see different instance IDs each time.

First win

If you see two different instance IDs as you refresh, your load balancer is working. Traffic is being spread across multiple EC2 servers. Take a screenshot of both pages side by side.

6
Trigger a scale-out
20 min

Now the fun part — let's force a CPU spike and watch Auto Scaling do its thing.

SSH into one of the EC2 instances:

ssh -i your-key.pem ec2-user@<EC2-PUBLIC-IP>

Now run stress to peg the CPU at 100% for 10 minutes:

stress --cpu 2 --timeout 600s & # --cpu 2 = use 2 CPU workers # --timeout 600s = run for 10 minutes # & = run in background so SSH stays usable

Now watch the magic. Open three browser tabs:

  1. EC2 → Instances — count rises from 2 to 3, then 4...
  2. EC2 → Auto Scaling Groups → cloudwithshad-asg → Activity — shows live scaling events
  3. CloudWatch → Metrics → EC2 → CPU utilization — see the spike that triggered it

Within 3-5 minutes, you'll see ASG launch new instances. After your stress test ends and CPU drops, give it 10-15 minutes — ASG will scale back down to the desired capacity (2).

Screenshot worthy moment

Take a screenshot of the ASG Activity history showing both a scale-out event ("Launching a new EC2 instance") AND a later scale-in event ("Terminating EC2 instance"). That's your Lab 5 submission.

If scale-out is slow

Auto Scaling uses a 5-minute "cooldown" by default — it waits to see if the spike is sustained before reacting. This is intentional. In production you'd never want ASG launching servers for a 30-second CPU spike.

7
Clean up (DO NOT SKIP — costs money!)
10 min

Out of all the labs in this bootcamp, this is the most expensive one to forget about. An ALB left running for a month costs ~$16. Multiple weeks = real money.

⚠ Cleanup order matters!

  • Auto Scaling Group: EC2 → ASG → cloudwithshad-asg → Delete. This terminates all EC2 instances automatically. Wait ~2 minutes.
  • Load Balancer: EC2 → Load Balancers → cloudwithshad-alb → Actions → Delete
  • Target Group: EC2 → Target Groups → cloudwithshad-tg → Actions → Delete
  • Launch Template: EC2 → Launch Templates → cloudwithshad-web-template → Actions → Delete
  • Security Groups: Delete alb-sg and web-sg (EC2 → Security Groups)
  • Confirm: EC2 → Instances should show 0 running instances
Don't delete the ALB before the ASG

If you delete the ALB first, the ASG keeps running and trying to register new instances with a dead target group. Always: ASG → ALB → TG → Template.

🚀

Lab 5 complete!

You just built the same auto-scaling pattern that powers every major web service in the world. Netflix, Spotify, Airbnb, your bank — all of them use exactly this.

Next: Lab 6 — CI/CD Pipeline (GitHub → AWS)