Key Concepts
What is Load Balancing?
Load balancing distributes incoming traffic across multiple servers (EC2 instances) to ensure:
• Better performance (no single instance is overloaded).
• Higher availability (if one server fails, traffic shifts to healthy ones).
• Smooth scaling (add/remove servers without downtime).
Elastic Load Balancing (ELB)
AWS provides Elastic Load Balancing (ELB) to automatically manage traffic distribution.
Types of Load Balancers:
1. Application Load Balancer (ALB) → Works at Layer 7 (HTTP/HTTPS). Supports advanced routing (path-based, host-based) and microservices.
2. Network Load Balancer (NLB) → Works at Layer 4 (TCP/UDP). Designed for high performance and ultra-low latency.
3. Classic Load Balancer (CLB) → Legacy, works at Layer 4 & 7, supports basic routing.
Step by step solution.
Task 1: Setup EC2 Instances
- Launch 2 Ubuntu EC2 instances.
- Add a User Data script to install Apache web server:
#!/bin/bash
apt update -y
apt install apache2 -y
echo "<h1>Hello from [Your Name]</h1>" > /var/www/html/index.html
systemctl start apache2
systemctl enable apache2
<h1>TrainWithShubham Community is Super Awesome :)</h1>
- Copy public IPs → paste in browser → you should see your custom pages.
Task 2: Create an Application Load Balancer (ALB)
1. Go to EC2 → Load Balancers → Create Load Balancer → Application Load Balancer.
2. Configure:
• Scheme: internet-facing
• Listeners: HTTP (port 80)
• VPC + Subnets: choose available ones
3. Create a Target Group → add both EC2 instances.
4. Verify health checks → once healthy, copy the ALB’s DNS name.
5. Paste ALB DNS in browser → it should alternate responses between your two Apache servers.
Top comments (0)