Setting up an Application Load Balancer with AWS EC2
Load Balancing Web Traffic with Application Load Balancer (ALB)
Imagine you have an Apache web application hosted on multiple EC2 instances, and you want to distribute incoming HTTP traffic evenly across these instances.
Here's how you can set up an ALB to achieve this:
Follow me blindly!
Infrastructure Readiness:
Let's create 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server
#!/bin/bash sudo apt update -y sudo apt install apache2 -y sudo systemctl start apache2 sudo systemctl enable apache2
Login to the ApacheServer1 and modify the index.html file to include your name so that when your Apache server is hosted, it will display your name.
For 2nd instance which includes " TrainWithShubham Community"
Copy the public IP address of your EC2 instances.
Open a web browser and paste the public IP address into the address bar.
You should see a webpage displaying information about your PHP installation with your message
cd /var/www/html vim index.html
Create a Target Group:
Go to the EC2 console and scroll down, the left corner has the Target group as shown below. Click on it and click on Create Target Group
Give name to your Target Group and Select Target Type as Instances, , Protocol HTTP, Port 80, VPC Deafult. Keep Health Check Settings as Default.
Click on Create
Your Target Group is created!
Create an Application Load Balancer:
Navigate to the AWS Management Console and go to the EC2 service.
Under the "Load Balancers" section, click "Create Load Balancer" and choose "Application Load Balancer."
Select Application Load Balancer, Configure the load balancer settings, mention alb name, Scheme Internet facing, IP address tupe IPV4, including listeners (port 80 for HTTP)
Select Default SG
Select the target group that we have created before
Your Traget group has added both the EC2 Instances where Apache web is configured!
Review everything and Create.
Your Load Balancer is created!
Load Balancer is active and ready to show its magic!
Hit DNS URL and see how Application Load Balancer is working!
Conclusion
AWS load balancers are essential tools for achieving high availability, scalability, and fault tolerance in your cloud infrastructure. They are versatile and can be customized to meet the specific needs of your applications, whether they are web-based, API-driven, or something else entirely.
By understanding the different types of AWS load balancers and how to configure them, you can ensure that your applications remain highly responsive and available to users, even during traffic spikes or instance failures. Leveraging load balancers is a fundamental step in building resilient and scalable architectures on AWS, contributing to a seamless and reliable user experience.
Subscribe to my newsletter
Read articles from Kshitija Bartakke-Malwade directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Kshitija Bartakke-Malwade
Kshitija Bartakke-Malwade
DevOps is all about collaboration and learning from each other! Let's connect on Hashnode and exchange ideas, tips, and success stories! ๐ค ๐ https://hashnode.com/@Kshitijaa ๐ง kshitijabartakke17@gmail.com ๐ธ www.linkedin.com/in/kshitija-bartakke-malwade-39678b141 Join me on this thrilling DevOps journey as we embrace innovation, automation, and a brighter future for software development! ๐ Let's build a seamless digital world together! ๐๐ป #DevOps #Automation #ContinuousInnovation #CI/CD #InfrastructureAsCode