AWS Certified Cloud Practitioner / ELB & ASG - Elastic Load Balancing & Auto Scaling Groups

Application Load Balancer (ALB) Hands On

🖼️ What you're building

One entry point Application Load Balancer (the ALB) spreads traffic across two servers.


1️⃣ Launch two EC2 instances

  • Instances: 2 (name them "My first Instance", "My second Instance")

  • AMI: Amazon Linux 2 🐧

  • Type: t3.micro or t2.micro (Free Tier) 💸

  • Key pair: None ❌ ( Because we don't need SSH access for this)

  • Security group: Select Existing Security Group

Add a user data script at launch — it runs automatically and makes each instance serve a "Hello World" page over HTTP, no manual setup needed.

#!/bin/bash
# Use this for your user data (script from top to bottom)
# install httpd (Linux 2 version)
yum update -y yum install -y httpd systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html

Verify: open each instance's public IPv4 in your browser. You should see:

💡 Ensure the URL uses http://, not https://. Timeout or 503 errors are often caused by this, so please double-check.

Hello World from Instance X

2️⃣ Create the Application Load Balancer

  • Go To EC2 → Load Balancing → Load Balancers → Click Create load balancer

  • Click Create button under Application Load Balancer (ALB)

  • Name: DemoALB

  • Scheme: Internet-facing 🌍

  • IP type: IPv4

  • Availability Zones: Select all — enables high availability in Network Mapping

  • Security group: New: demo-sg-load-balancer, allow HTTP (80) from anywhere

  • Reload Security Group and Add the newly created security group


3️⃣ Create a target group

A target group is just the set of instances that receive traffic from the ALB.

  • Name: demo-tg-alb

  • Target type: Instances 💻

  • Protocol / Port: HTTP / 80

Register both EC2 instances as targets. Confirm both show up in the group.


4️⃣ Connect the ALB to the target group

Add a listener: HTTP (port 80) → target group.

ALB ⚖️ → EC2 Instances 💻

5️⃣ Launch and test

  • Wait for the ALB status to go from Provisioning to Active. (It might take few minutes)

  • Copy the ALB's DNS name and open it in your browser.

  • Refresh a few times — you'll see the response alternate:

Hello World from Instance 1
Hello World from Instance 2

💡 Ensure the DNS URL uses http://, not https://. Timeout or 503 errors are often caused by this, so please double-check.

✅ That alternation is the load balancer working.


6️⃣ Health checks

The ALB continuously checks each instance and only routes traffic to the ones that are healthy.

Try it — simulate a failure:

  1. Stop Instance 1 in the EC2 console.

  1. In the target group, its status flips to Unhealthy / Unused.

  1. Refresh the ALB's DNS — only Instance 2 responds now. Failure handled automatically.( No Instance 1 ip)

Recovery: (Do It Yourself)

  1. Start Instance 1 again.

  2. Wait for its status to go Initial → Healthy.

  3. Refresh — both instances respond again.


🧐 What you just practiced

  • Load balancing: spreads traffic across multiple instances

  • High availability: the app survives a single instance failing

  • Health checks: unhealthy instances are removed from rotation automatically

  • Single entry point: one DNS name in front of many servers


🤫 Exam tips

  • ALB = HTTP/HTTPS, Layer 7 🌐

  • A target group = the EC2 instances behind the ALB 💻

  • Health checks handle failure automatically 🛡️

  • Spanning multiple AZs = high availability 🌍


🔥 Takeaway

You built a system that distributes traffic, survives failures, stays highly available, and scales easily — the foundation of modern cloud architecture.