Skip to main content

Command Palette

Search for a command to run...

Project : Deploy App on EC2 + Load Balancer

Updated
3 min read
T

Learning DevOps Engineer passionate about cloud computing, containerization, and automation. Currently exploring Docker, AWS, and CI/CD pipelines to build scalable and efficient workflows. Documenting my learning journey in blog. stay tuned with me for learning.

What you will build

  • 2 EC2 servers (your app runs here)

  • 1 Load Balancer (distributes traffic)

  • Simple web app (HTML)

  • Public URL to access your app

Architecture :

User → Load Balancer → EC2 Instance 1 / EC2 Instance 2

STEP 1 : Launch EC2 Instances

Create 2 instances:

  • Name: ec2-1, ec2-2

  • AMI: Amazon Linux 2

  • Instance type: t3.micro (free tier)

  • Key pair: create/download

  • Security group:

    • Allow:

      • SSH (22)

      • HTTP (80)

👉 Launch both instances

STEP 2 : Connect to EC2

ssh -i your-key.pem ec2-user@your-public-ip

STEP 3 : Install Web Server (Apache)

Run on BOTH instances :

sudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd

STEP 4 : Create Simple Web App

On Instance 1 :

echo "Hello from Server 1" | sudo tee /var/www/html/index.html

On Instance 2 :

echo "Hello from Server 2" | sudo tee /var/www/html/index.html

STEP 5 : Test Individually

Open browser :

On Instance 1 :

http://<EC2-1 public ip>

On Instance 2 :

http://<EC2-2 public ip>

STEP 6 : Create Load Balancer

Go to EC2 → Load Balancers

Choose :
👉 Application Load Balancer (ALB)

Configure:

  • Name: my-lb

  • Scheme: Internet-facing

  • Listener: HTTP (80)

STEP 7 : Configure Security Group for Load Balancer

Allow :

  • Name : my-sg-lb

  • HTTP (80) from Anywhere (0.0.0.0/0)

STEP 8: Create Target Group

  • Type: Instances

  • Protocol: HTTP

  • Port: 80

👉 Register BOTH EC2 instances

STEP 9 : Attach Target Group to Load Balancer

  • Select your target group

  • Complete creation

STEP 10 : Test Load Balancer

Copy DNS name of Load Balancer

👉 Refresh multiple times

✔ You will see:

  • "Hello from Server 1"

  • "Hello from Server 2"

🎉 That means Load Balancing is working !

What You Learned :

  • What is EC2 (virtual server)

  • What is Load Balancer

  • Traffic distribution

  • High availability

  • Basic Linux + Apache setup

Conclusion

This project successfully demonstrates how to deploy a highly available web application on Amazon Web Services using EC2 instances and an Application Load Balancer.

By configuring multiple EC2 instances and integrating them with a load balancer, we ensured that incoming traffic is efficiently distributed, improving both performance and fault tolerance. During the setup, practical challenges such as connectivity issues, target group configuration, and health checks were identified and resolved, providing a deeper understanding of real-world cloud deployment scenarios.

This project highlights key concepts like:

  • Infrastructure setup using EC2

  • Load balancing and traffic routing

  • High availability and scalability

  • Troubleshooting common AWS issues (timeouts, 503 errors)

Overall, it serves as a strong foundation for advancing into DevOps practices, including automation, containerization, and CI/CD pipeline implementation.