Day 41: Setting up an Application Load Balancer with AWS EC2 πŸš€ ☁

Day 41: Setting up an Application Load Balancer with AWS EC2 πŸš€ ☁

Β·

5 min read

Hi, I hope you had a great day yesterday learning about the launch template and instances in EC2. Today, we are going to dive into one of the most important concepts in EC2: Load Balancing.

What is Load Balancing?

  • Load balancing is the distribution of workloads across multiple servers to ensure consistent and optimal resource utilization. It is an essential aspect of any large-scale and scalable computing system, as it helps you to improve the reliability and performance of your applications.

Elastic Load Balancing:

  • Elastic Load Balancing (ELB) is a service provided by Amazon Web Services (AWS) that automatically distributes incoming traffic across multiple EC2 instances. ELB provides three types of load balancers:

1 . Application Load Balancer (ALB) - operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices.

  • Read more from here

2 . Network Load Balancer (NLB) - operates at layer 4 of the OSI model and is ideal for applications that require high throughput and low latency.

  • Read more from here

3 . Classic Load Balancer (CLB) - operates at layer 4 of the OSI model and is ideal for applications that require basic load balancing features.

🎯 Today's Tasks:

Task 1:

  • Go to EC2 Dashboard in the AWS management console.

  • Click on Launch instance and write the Name and tags of your instance. choose an Ubuntu AMI. Choose instance type t2.micro and key pair as your requirement. Select to Allow HTTPS.

  • In the "Configure Instance" step, scroll down to the "Advanced Details" section. Enter the following script in the "User data" field to install Apache and click on Launch instance.

Bash

#!/bin/bash
sudo apt-get update
sudo apt-get install -y apache2
sudo systemctl enable apache2
sudo systemctl start apache2
echo "DevOpsParthu Community is Super Aweasome :)" > /var/www/html/index.html

  • Launch Second instances also as you did for 1 instance with this user data script. But change index.html file as given below and Launch the instance.

Bash

#!/bin/bash
sudo apt-get update
sudo apt-get install -y apache2
sudo systemctl enable apache2
sudo systemctl start apache2
echo "TrainWithShubham Community is Super Aweasome :)" > /var/www/html/index.html

  • Once the instances are running, copy their Public IP addresses. Open a web browser and paste the Public IP address of each EC2 instance into the address bar. You should see a webpage displaying your name on one instance and "DevOpsParthu Community is Super Aweasome :)" on the other instance "TrainWithShubham Community is Super Aweasome :)".

Task 2:

  • Go to the EC2 dashboard in the AWS Management Console. Click on "Load Balancers" in the left sidebar.

  • Click on "Create Load Balancer" and select "Application Load Balancer".

  • Configure the load balancer with a name, listener (HTTP on port 80), and availability zones and select mapping zones in your region as you wanted to create. In my case selecting all.

  • Now You have to create security Group for load balancer. By default AWS provides you a group and also you can select launch-wizard-1, 2, 3, 4 in Security group.But it Good practice to create new one so click on Create New Security Group in Security Group Section. It will take you to the new tab on browser. Fill your group name as you want & give Description. Set Inbound Rule to HTTP port 80 And keep rest all by default and click on create group and refresh your security group and select your group. In my case I selected launch-wizard-1, 2, 3, 4 and i create security group also.

  • Now in Listeners and routing Section there you find the select target group but we don't have the Target group So we click on Create Target Group and it will take you to a new browser. Now you have to Select Target Type as a Instance Because we use our ec2 instance for load balancing. If you want to set with ip select that. There is 4 Target types. Now enter the Target group name.

  • Scroll Down to bottom and click on Next. Now you see There is your all running instance so you have to select instance for load balancing And click on Include as pending below now you have a option to review targets review and click on create Target Group.

  • now you have a option to review targets review and click on create Target Group.

  • Come back go to the browsers Load Balancer tab and refresh the target group section and there you will find your target group that you created now select that.

  • Scroll down and there you will see the summary about load balancer review it and click on create load balancer.

  • Now you Successfully Created Load balancer for EC2 instance. click on view load balancer and see the all things about your Load balancer.

  • Now Its Time to test your Load Balancer. Copy the DNS name from Load balancer Description and paste in new browser tab and refresh it again and again you will see your two difference sentence in your servers file. If you didn't see that please wait for 2 min load balancer take time to active.


Happy Learning

Thanks For Reading! :)

-Sri ParthuπŸ’πŸ’₯

Β