Setting up an Application Load Balancer with AWS EC2 ๐Ÿš€ โ˜

Setting up an Application Load Balancer with AWS EC2 ๐Ÿš€ โ˜

ยท

4 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 (ELB)

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:

Application Load Balancer (ALB) - operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices. It supports advanced features such as path-based routing, host-based routing, and content-based routing, enabling flexible and granular traffic management.

Network Load Balancer (NLB) - operates at layer 4 of the OSI model and is ideal for applications that require high throughput and low latency. It is capable of handling millions of requests per second with ultra-low latency. NLB is commonly used for TCP and UDP-based workloads that require extreme scalability and high performance.

Classic Load Balancer (CLB) - operates at layer 4 of the OSI model and is ideal for applications that require basic load balancing features. While ALB and NLB provide more advanced features and better performance, CLB can still be suitable for simple applications or those that require backward compatibility.

๐ŸŽฏ Today's Tasks

Task: Launch two EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server and create an Application Load Balancer in EC2 using the AWS Management Console.

  1. Log in to the AWS Management Console and navigate to the EC2 service.

  2. Click on "Launch Instance" to start the instance creation process.

  3. Choose the Ubuntu AMI as the base image for your instances.

  4. Select the desired instance type and configure other instance details as needed.

  5. Continue through the remaining steps, configuring storage, security groups, and other settings as desired.

  6. Scroll down to the "Advanced Details" section.

  7. Enter the following script in the "User Data" field to install the Apache Web Server.

  8. Modify the index.html file to include your name so that when your Apache server is hosted, it will display your name.

Open Port 8080 for this server:

We can access the Apache default page using the Public Ip of the instance.

Also, do it for 2nd instance which includes

Copy the public IP address of your EC2 instances.

Create Load Balancing Application

  1. From the left-hand pane, click on "Load Balancers" under Load Balancing:

  2. After that Click on "Create Load Balancer" > Create "Application Load Balancer". Write your load balancer name and select the mapping zones in your region that you want to create.

  1. By default AWS provides you a group. It's good practice to create a Security Group for the load balancer.

It will take you to the new tab on the browser. Fill in your group name as you want & give a Description.

Set Inbound Rule to HTTP port 80. Keep rest all as it is (by default) and click on Create Group.

Now go to the security group section in the previous tab (ALB configuration) and refresh the list and search for the security group that you created now.

  1. Now in the "Listeners and Routing" section, click on "Create Target Group". It will take you to a new browser. Select Target Type as an Instance Because we use our ec2 instance for load balancing.

    Now enter the Target group name.

    1. 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

      You have an option to review targets, review them and click on create Target Group.

      You have an option to review targets, review them and click on create Target Group.

      We can see that the target "multiverse-secure-target" has been created:

      Go back to the "Create Application Load Balancer Tab" and refresh the target group section and should see the target group. Select the target group.

      Here you go, your ALB "first" has been created successfully.

      Verify that the ALB is working properly by checking the health status of the target instances and testing the load-balancing capabilities.

      Refresh it and you will see your Load Balancetwo difference sentence in your servers file. If you don't see that, wait for 2 min load balancer takes times to come in "active" state.

      Copy the DNS name and hit on the web URL:first-291695937.us-east-1.elb.amazonaws.com

ย