Introduction
In this tutorial, we'll walk through the process of setting up an Application Load Balancer (ALB) on AWS and integrating it with two EC2 instances running Apache Web Server. This will allow us to distribute incoming traffic across multiple instances, providing better availability and fault tolerance for our application.
Task 1: Launching EC2 Instances and Installing Apache
Launch EC2 Instances:
Open the AWS Management Console.
Navigate to the EC2 Dashboard.
Click on "Launch Instance."
Choose an Ubuntu AMI.
In the "Configure Instance Details" section, add the following script in the "User Data" field:
bash
#!/bin/bash apt-get update apt-get install -y apache2 echo "<html><body><h1>Your Name</h1></body></html>" > /var/www/html/index.html
- Complete the instance creation wizard, and launch two instances.
Modify Index.html:
SSH into each instance using the public IP addresses.
Edit the
/var/www/html/index.html
file on each instance.Instance 1: Add your name.
Instance 2: Add "TrainWithShubham Community is Super Awesome :)".
Copy Public IP Addresses:
- In the EC2 Dashboard, copy the public IP addresses of both instances.
Test Apache Web Server:
Open a web browser and paste the public IP addresses into the address bar.
You should see a webpage displaying information about your Apache installation, including your name and the community message.
Task 2: Setting up an Application Load Balancer (ALB)
Create an Application Load Balancer:
Navigate to the EC2 Dashboard and select "Load Balancers."
Click on "Create Load Balancer."
Choose "Application Load Balancer" and configure it.
Add listener (e.g., HTTP on port 80).
Configure security settings and create a new security group.
Review and create the ALB.
Configure Target Groups:
While creating the ALB, create a new target group or use an existing one.
Configure health checks and target registration settings.
Add EC2 Instances to the ALB:
In the ALB dashboard, go to the "Target Groups" tab.
Click on the target group you created.
Under "Targets," click "Edit" and add the two EC2 instances.
Verify ALB Functionality:
In the ALB dashboard, go to the "Description" tab to find the DNS name of your ALB.
Open a web browser and navigate to the ALB DNS name.
You should see the same webpage as before, but now the requests are being load-balanced between the two instances.
Check Health Status:
In the ALB dashboard, go to the "Target Groups" tab.
Select the target group and check the health status of your instances.
Conclusion
Congratulations! You've successfully set up an Application Load Balancer with AWS EC2 instances, enhancing the availability and scalability of your web application. This configuration is essential for handling increased traffic and ensuring a reliable user experience.
Follow me on LinkedIn.
Check out my GitHub profile.