π Load-Balanced Electro E-Commerce Website on AWS (Using AWS Load Balancer)
This project demonstrates how to deploy a highly available e-commerce website using Amazon Web Services (AWS). It uses two EC2 instances, an Application Load Balancer (ALB), and a custom VPC with public subnets β configured exactly as shown in the architecture diagram.
β Perfect for beginners learning AWS infrastructure, load balancing, and high availability!
π― Project Goal
- Deploy a Electro e-commerce website on two EC2 instances.
- Distribute incoming web traffic across both instances using an Application Load Balancer.
- Build a secure and scalable network architecture using VPC, subnets, and an Internet Gateway.
ποΈ Architecture Overview
-
VPC:
12.0.0.0/16 -
Public Subnets:
-
12.0.1.0/24β Hosts EC2 Instance 1 -
12.0.3.0/24β Hosts EC2 Instance 2
-
- EC2 Instances: 2 web servers (running Apache)
- Load Balancer: Application Load Balancer (HTTP on port 80)
- Target Group: Routes traffic to both healthy EC2 instances
- Internet Gateway: Enables public internet access
π Step-by-Step Implementation
1. *Create a Custom VPC *
- Go to VPC Dashboard β Your VPCs β Create VPC
- Name:
ecommerce-vpc - IPv4 CIDR:
12.0.0.0/16
- Name:
- Click Create
2. *Create Two Public Subnets *
-
Subnet 1:
- Name:
public-subnet-1a - VPC:
ecommerce-vpc - Availability Zone: e.g.,
us-east-2a - CIDR:
12.0.1.0/24β Matches diagram
- Name:
-
Subnet 2:
- Name:
public-subnet-2b - AZ:
us-east-2b - CIDR:
12.0.3.0/24
- Name:
3. Create and Attach an Internet Gateway
- Go to Internet Gateways β Create
- Name:
ecommerce-igw
- Name:
- After creation, attach it to
ecommerce-vpc
4. Configure Route Table for Public Access
- Go to Route Tables, select the main route table for your VPC
- Edit Routes β Add:
- Destination:
0.0.0.0/0 - Target:
ecommerce-igw
- Destination:
-
Associate this route table with both public subnets (
12.0.1.0/24and12.0.3.0/24)
5. Launch Two Ubuntu EC2 Instances
Launch two EC2 instances using the Ubuntu 22.04 LTS AMI:
-
AMI:
Ubuntu 22.04 LTS (x86_64)β search in AMI catalog -
Instance Type:
t2.micro(Free Tier eligible) -
Network:
ecommerce-vpc -
Subnet:
- Instance 1 β
public-subnet-1a(12.0.1.0/24) - Instance 2 β
public-subnet-2b(12.0.3.0/24)
- Instance 1 β
- Auto-assign public IP: β Enable
-
Security Group: Create new
web-sgwith:- Inbound Rules:
- HTTP (Port 80) β Source:
0.0.0.0/0 - SSH (Port 22) β Your IP (or
0.0.0.0/0for testing)
- Paste the script below in the data field of the EC2 instance under "Additional settings" to install Apache2 and update the server:
#!/bin/bash
# Update system packages
apt-get update -y
# Install Apache2
apt-get install -y apache2
# Ensure Apache starts on boot
systemctl enable apache2
systemctl start apache2
# Ensure /var/www/html exists and has correct ownership
mkdir -p /var/www/html
chmod -R 755 /var/www/html
# Optional: Create a simple test page
echo "<h1>Apache2 is running on Server1</h1><p>Instance provisioned automatically on Server1.</p>" > /var/www/html/index.html
Repeat step 5 to create the second EC2 instance
- In the echo section of the script, change the h1 tag to Apache2 is running on Server2 to distinguish the servers.
6. Create an Application Load Balancer (ALB)
- Go to EC2 β Load Balancers β Create Load Balancer
- Choose Application Load Balancer
- Name:
ecommerce-alb - Scheme:
Internet-facing - IP address type:
IPv4 - Listeners:
HTTP (Port 80) - Availability Zones: Select your VPC and both
public subnets (12.0.1.0/24 and 12.0.3.0/24) - Security Group: Create or select
alb-sgallowing HTTP from0.0.0.0/0 - Target Group:
- Create new:
ecommerce-tg - Protocol:
HTTP,Port: 80, Health check path:/ - Register both Ubuntu EC2 instances by selecting them and click
Include as pending below. - Review and Create
7. Test the Load Balancer
- Wait 2β5 minutes for the ALB to become active
- Copy the DNS name of your ALB from the AWS console
- Open in browser:
http://<your-alb-dns-name> - Refresh multiple times β you should see alternating messages:
- βServer 1 (Subnet: 12.0.1.0/24)β
- βServer 2 (Subnet: 12.0.3.0/24)β
- Confirm both instances show Healthy in Target Groups
8. Deploy Your Website Files on Ubuntu
Upload your website files (e-commerce web files)
To upload you website files:
πΉ Step 1: Open Git Bash in Your Website Folder
β
Open your terminal and navigate to your project folder.
C:\Users\laolu\Documents\Realprojects\AWS projects\ALB-ecommerce\Electro
πΉ Step 2: Set Secure Permissions on Your Key
chmod 400 test-ALB-demo.pem
πΉ Step 3: Copy Files to Server 1 (3.139.70.220)
β
Run this command (all on one line):
scp -i test-ALB-demo.pem -r Electro/* ubuntu@3.139.70.220:/tmp/
πΉ Step 4: Move Files into Web Folder on Server 1
β
Now log in to Server 1:
ssh -i test-ALB-demo.pem ubuntu@3.139.70.220
β
Once logged in, run these 3 commands (copy/paste one at a time):
# 1. Delete default Apache files
sudo rm -rf /var/www/html/*
# 2. Move your files from /tmp to the web folder
sudo mv /tmp/* /var/www/html/
πΉ Step 5: Copy Files to Server 2 (18.217.149.70)
β
Run this command (all on one line):
scp -i test-ALB-demo.pem -r Electro/* ubuntu@18.217.149.70:/tmp/
β
Wait for the files to finish copying.
πΉ Step 6: Move Files into Web Folder on Server 2
β
Log in to Server 2:
ssh -i test-ALB-demo.pem ubuntu@18.217.149.70
β
Run the same 3 commands:
sudo rm -rf /var/www/html/*
sudo mv /tmp/* /var/www/html/
exit
β
Done! π
Your entire E-commerce website is now live on both servers.
π Test It Out
- Open your browser and go to:
- β€
http://3.139.70.220β should show your real website β€
http://18.217.149.70β same websiteFrom your Load Balancer, visit its DNS name and refresh β you should see the same site served from both servers.
Load Balancer DNS:
http://ecommerce-alb-178280318.us-east-2.elb.amazonaws.com/
Top comments (0)