How to Create ELB in AWS with EC2 Instances in Different Availability Zones (Step-by-Step Guide)
Flow:
User โ ELB (ALB Listener) โ Target Group โ EC2 Instances (in different AZs)

๐ Introduction
In this guide, you will learn how to:
- Launch 2 EC2 instances in different Availability Zones
- Create a Target Group
- Configure an Application Load Balancer (ELB)
- Distribute traffic for high availability
We will use:
- Amazon EC2
- Elastic Load Balancing
๐น Step 1: Launch EC2 Instances (in Different AZs)
๐ ๏ธ Create First Instance (AZ-1)
- Go to EC2 Dashboard โ Launch Instance
- Name:
web-server-1 - AMI: Amazon Linux
- Instance type: t2.micro
- Select Availability Zone (e.g., ap-south-1a)
- Security Group:
- Allow HTTP (80)
- Allow SSH (22)
๐ User Data:
#!/bin/bash
yum update -y
yum install -y httpd
systemctl enable httpd
systemctl start httpd
echo "Server 1 - AZ1 Working" > /var/www/html/index.html
๐ ๏ธ Create Second Instance (AZ-2)
Repeat same steps:
- Name:
web-server-2 - Availability Zone: ap-south-1b
๐ User Data:
#!/bin/bash
yum update -y
yum install -y httpd
systemctl enable httpd
systemctl start httpd
echo "Elb and auto scalling second server working " > /var/www/html/index.html
๐น Step 2: Create Target Group
- Go to EC2 โ Target Groups
- Click Create Target Group
โ๏ธ Configuration:
- Target type: Instances
- Name:
my-target-group - Protocol: HTTP
- Port: 80
- VPC: Select your VPC
๐ Health Check:
- Path:
/ - Protocol: HTTP
๐ Register Targets:
- Select both instances (
web-server-1,web-server-2) - Click Include as pending
- Click Create Target Group
๐น Step 3: Create Application Load Balancer (ELB)
- Go to EC2 โ Load Balancers
- Click Create Load Balancer
- Choose: Application Load Balancer
โ๏ธ Basic Settings:
- Name:
my-alb - Scheme: Internet-facing
- IP type: IPv4
โ๏ธ Network Mapping:
- Select at least 2 subnets (different AZs)
โ๏ธ Security Group:
- Allow HTTP (Port 80)
โ๏ธ Listener:
- Protocol: HTTP
- Port: 80
โ๏ธ Routing:
- Select existing Target Group:
my-target-group
๐ Click Create Load Balancer
๐น Step 4: Verify Health Check
- Go to Target Group โ Targets
- Status should be: Healthy โ
๐ If not:
- Check Apache is running
- Check port 80 open
๐น Step 5: Test Load Balancer
- Copy Load Balancer DNS
- Paste in browser
๐ Output will switch between:
Server 1 - AZ1 WorkingServer 2 - AZ2 Working
๐ This confirms:
โ
Load balancing working
โ
Multi-AZ setup working

Total Page Visits: 1691 - Today Page Visits: 59
