🎯 Objective
Set up an Application Load Balancer (ALB) in AWS to receive HTTP traffic and forward requests to an application running on an EC2 instance.
In this task, we will understand and configure:
The final traffic flow will be:
Internet
↓
Application Load Balancer
↓
Target Group
↓
EC2 Instance
↓
Application🧠 Concept
An Application Load Balancer (ALB) distributes incoming HTTP/HTTPS requests to registered backend targets.
Instead of users accessing an EC2 instance directly:
User
↓
EC2we place a load balancer in front:
Internet
│
▼
Application Load Balancer
│
▼
Target Group
│
┌───────┴───────┐
▼ ▼
EC2-1 EC2-2Even when starting with only one EC2 instance, using a load balancer provides an architecture that can later support multiple instances.
# 🏗️ Main Components
The important components are:
Application Load Balancer
│
├── Security Group
│
├── Listener
│
└── Target Group
│
├── Health Check
│
└── EC2 InstanceEach component has a different responsibility.
1️⃣ Application Load Balancer
The Application Load Balancer is the public entry point for the application.
It receives HTTP or HTTPS requests and forwards them to healthy targets.
For example:
User
│
│ HTTP :80
▼
ALB
│
│ Forward
▼
Target Group
│
▼
EC2An ALB operates at Layer 7 — Application Layer, so it understands HTTP and HTTPS traffic.
It can support features such as:
# 🚀 Step 1: Prepare the EC2 Instance
Before configuring the load balancer, make sure the EC2 instance is running a web application.
For example:
sudo systemctl status httpdor:
sudo systemctl status nginxTest locally from the instance:
curl http://localhostThe application must be reachable on the port that will be configured in the target group.
For example:
Apache/Nginx
↓
TCP Port 80# 🎯 Step 2: Create a Target Group
Go to:
EC2
↓
Target Groups
↓
Create target groupChoose:
Target type → InstancesConfigure the target group.
Example:
Target Type → Instances
Protocol → HTTP
Port → 80
VPC → Same VPC as EC2🧠 What Is a Target Group?
A Target Group defines where the load balancer should send requests.
ALB
│
│ Forward traffic
▼
Target Group
│
├── EC2 Instance 1
├── EC2 Instance 2
└── EC2 Instance 3The load balancer itself does not directly define all backend servers.
Instead:
ALB
↓
Target Group
↓
Registered Targets# 🖥️ Step 3: Register EC2 Instance
During target group configuration, register the EC2 instance.
Select:
EC2 InstanceThen:
Include as pending belowand create/save the target group.
The architecture becomes:
Target Group
│
└── EC2 Instance
│
└── Application :80# ❤️ Step 4: Configure Health Check
The target group periodically checks whether the EC2 application is healthy.
Example:
Protocol → HTTP
Path → /
Port → Traffic PortThe ALB sends requests similar to:
GET /to the EC2 instance.
If the application responds successfully:
Target
↓
Healthy ✅If the health check repeatedly fails:
Target
↓
Unhealthy ❌The load balancer does not normally route application traffic to unhealthy targets.
# 🔐 Step 5: Configure Security Groups
Security Groups act as virtual firewalls around AWS resources.
For this architecture, there are ideally two security groups:
Internet
│
▼
ALB Security Group
│
▼
Application Load Balancer
│
▼
EC2 Security Group
│
▼
EC2 Instance🌐 ALB Security Group
The ALB needs to receive traffic from users.
For HTTP:
Inbound Rule
Type → HTTP
Protocol → TCP
Port → 80
Source → 0.0.0.0/0For HTTPS:
Type → HTTPS
Protocol → TCP
Port → 443
Source → 0.0.0.0/0This allows internet users to reach the load balancer.
# 🔒 EC2 Security Group
The EC2 instance should accept application traffic from the ALB, rather than exposing the application port directly to the entire internet.
For example:
Inbound Rule
Type → HTTP
Protocol → TCP
Port → 80
Source → ALB Security GroupThe important difference is:
❌ Less Restricted
Internet
│
│ :80
▼
EC2
✅ Better
Internet
│
│ :80
▼
ALB
│
│ :80
▼
EC2Using the ALB's security group as the EC2 inbound source limits application traffic to requests coming through the load balancer.
# 🚦 Step 6: Create the Application Load Balancer
Go to:
EC2
↓
Load Balancers
↓
Create Load Balancer
↓
Application Load BalancerConfigure:
Scheme → Internet-facing
IP address type → IPv4Choose:
For an internet-facing ALB, select subnets that provide the required public-facing network connectivity.
# 🎧 Step 7: Configure Listener
A Listener waits for incoming connections on a specific protocol and port.
For HTTP:
Protocol → HTTP
Port → 80Configure the default action:
Forward to
↓
Target GroupThe request path is now:
User
│
│ HTTP :80
▼
ALB Listener
│
│ Forward
▼
Target Group
│
▼
EC2 :80# 🔍 Step 8: Verify Target Health
Open:
EC2
↓
Target Groups
↓
Select Target Group
↓
TargetsCheck the registered instance.
Expected:
Status → HealthyIf it shows:
Unhealthycheck:
# 🌍 Step 9: Get the ALB DNS Name
AWS provides a DNS name for the load balancer.
It looks similar to:
my-alb-123456789.us-east-1.elb.amazonaws.comYou normally access the ALB using this DNS name rather than an ALB IP address.
# 🧪 Step 10: Test the Load Balancer
Test using:
curl http://<ALB-DNS-NAME>Or open:
http://<ALB-DNS-NAME>in a browser.
If everything is configured correctly:
Browser
│
▼
ALB DNS
│
▼
Listener :80
│
▼
Target Group
│
▼
Healthy EC2
│
▼
Web Application ✅# 🔐 Understanding Inbound Rules
Inbound rules determine who can initiate traffic to a resource.
For this architecture:
ALB
Internet
│
│ Allowed :80
▼
ALB Security GroupExample:
HTTP | TCP | 80 | 0.0.0.0/0EC2
ALB
│
│ Allowed :80
▼
EC2 Security GroupExample:
HTTP | TCP | 80 | ALB-Security-GroupThis creates a controlled traffic path:
Internet
│
│ Allowed
▼
ALB
│
│ Allowed
▼
EC2# 🔄 Complete Request Flow
When a user opens the application:
1. User sends HTTP request
↓
2. DNS resolves ALB hostname
↓
3. ALB Security Group checks traffic
↓
4. Listener receives request on :80
↓
5. Listener forwards to Target Group
↓
6. Target Group selects healthy target
↓
7. EC2 Security Group allows ALB traffic
↓
8. EC2 web server processes request
↓
9. Response returns through ALB
↓
10. User receives response# ⚠️ Common Issue: Target Shows Unhealthy
If the target becomes:
Unhealthyfirst verify the application:
curl http://localhostThen check:
sudo systemctl status httpdor:
sudo systemctl status nginxAlso verify:
Target Group Port
=
Application PortFor example:
Apache → 80
Target Group → 80and ensure the EC2 Security Group allows traffic from the ALB Security Group.
# 🧠 Load Balancer vs Target Group
These two concepts are easy to confuse.
Load Balancer
│
│ Receives requests
▼
Target Group
│
│ Defines backend targets
▼
EC2 InstancesLoad Balancer
Responsible for:
Receiving Traffic
Routing
Listeners
HTTP/HTTPSTarget Group
Responsible for:
Backend Targets
Target Ports
Health Checks
Healthy/Unhealthy Status# 📈 Why Use a Load Balancer?
Suppose initially we have:
ALB
│
▼
EC2-1As traffic increases, additional instances can be registered:
ALB
│
┌──────┼──────┐
▼ ▼ ▼
EC2-1 EC2-2 EC2-3The ALB can distribute incoming requests across healthy registered targets.
This helps support:
# 🧪 Validation Checklist
# 📌 Summary
The four main concepts are connected like this:
Internet
│
│ HTTP :80
▼
┌─────────────────┐
│ Inbound Rule │
│ 0.0.0.0/0 :80 │
└────────┬────────┘
▼
┌─────────────────┐
│ Security Group │
└────────┬────────┘
▼
┌─────────────────┐
│ ALB │
│ Listener :80 │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Target Group │
│ Health Checks │
└────────┬────────┘
│
▼
┌─────────────────┐
│ EC2 Security │
│ Group │
└────────┬────────┘
▼
┌─────────────────┐
│ EC2 Instance │
│ Web Server :80 │
└─────────────────┘The key takeaway is:
> The Application Load Balancer receives requests, its listener forwards them to a Target Group, the Target Group selects healthy EC2 targets, and Security Group inbound rules control which traffic is allowed at each layer.