Task 1: Launch 2 EC2 Instances and Install Apache
Step 1: Launch EC2 Instances
Log in to AWS Console.
Go to the EC2 Dashboard.
Click on “Launch Instance.”
Select “Ubuntu Server” as the AMI (Amazon Machine Image).
Choose an instance type (e.g., t2.micro if you're on free tier).
Click “Next” until you reach “Advanced Details.”
Step 2: Install Apache Automatically (Using User Data)
Scroll down to “Advanced Details” and expand the section.
In the “User Data” field, paste the following commands:
#!/bin/bash sudo apt update sudo apt install -y apache2 sudo systemctl start apache2 sudo systemctl enable apache2
Continue with the next steps: Add Storage, Configure Security Group (allow HTTP (port 80) and SSH (port 22)), and then Launch the Instance.
Repeat the steps to create the second instance.
Step 3: Modify Web Page (index.html) on Both Instances
Connect to the first EC2 instance using SSH:
ssh -i /path/to/your-key.pem ubuntu@<EC2-Public-IP>
Check Apache Status:
sudo systemctl status apache2
Edit the Default Web Page:
sudo nano /var/www/html/index.html
Add your name, e.g.,
Welcome to John's Server!
Press Ctrl + O to save, then Ctrl + X to exit.
Repeat the same for the second instance but update the content to:
#For First Instance This is Server A #For Second Instance This is Server B
Test in a Browser:
Copy the public IP of each instance.
Open the browser and paste the IP. You should see your custom message.
Task 2: Create an Application Load Balancer (ALB)
Step 1: Set Up the Load Balancer
Go to the EC2 Dashboard.
On the left menu, click “Load Balancers” → “Create Load Balancer.”
Choose “Application Load Balancer” and click “Create.”
Set a name for the load balancer.
Under Listeners, select HTTP (port 80).
Step 2: Configure Security and Availability
Choose the same VPC and Availability Zones as your EC2 instances.
Assign a Security Group that allows HTTP (port 80).
Step 3: Create a Target Group
Choose “Create Target Group.”
Select “Instances” as the target type.
Name the target group and select HTTP (port 80).
Under Targets, add both EC2 instances from Task 1.
Finish setup and review everything before creating.
Step 4: Test the Load Balancer
Go back to the Load Balancer page.
Copy the DNS name of the load balancer (something like
alb-1234567890.us-east-1.elb.amazonaws.com
).Open the DNS name in your browser.
Result:
Refresh the page multiple times.
You should see the content switching between the two messages:
Name from the first instance - This is Server A
Name from the second instance - This is Server B
This proves that the load balancer is distributing traffic evenly.