Load Balancer falls under the EC2 services of AWS. An Application Load Balancer works at the seventh layer of the Open Systems Interconnection (OSI) model, the application layer. We can add and remove targets from our load balancer as per our needs without affecting the flow of requests to the application. Application Load Balancer supports for path-based routing: forward requests based on the URL in the request, host-based routing: forward requests based on the host field in the HTTP header, routing based on fields in the request, registering targets by IP address: targets outside the VPC for the load balancer can also be added. These are a few of the benefits of using the Application Load Balancer.

For more information about the Application Load Balancer click here.

With Application Load Balancer we only pay for what we use. Click here to know more about its pricing.

In this article, we will see how to create an Application Load Balancer, register instances, and access the Load Balancer using its DNS.

Pre-requisites

  1. AWS Account (Create if you don’t have one). 
  2. One or more than one EC2 instance with Apache running on them.

What we will do?

  1. Login to AWS
  2. Create an Application Load Balancer and access the Apache Application using DNS of the Load Balancer.

Login to AWS

  1. Click here to go to AWS Login Page.

When we hit the above link, we will see a web page as follows where we are required to log in using our login details.

<img alt="AWS Login" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.02_.03_PM_.png617ac70298235.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="418" loading="lazy" src="data:image/svg xml,” width=”750″>

Once we login into AWS successfully, we will see the main console with all the services listed.

Create  an Application Load Balancer and access the Apache Application using DNS of the Load Balancer

To create an Application Load Balancer, click on “Services” at the top left menu and search for “EC2” and click on the result. 

<img alt="Create Application Load Balancer" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.02_.26_PM_.png617ac702e1049.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="418" loading="lazy" src="data:image/svg xml,” width=”750″>

On the main EC2 dashboard, scroll down and click on “Load Balancer” available in the left navigation menu .

<img alt="Resources" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.02_.40_PM_.png617ac703275bf.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="417" loading="lazy" src="data:image/svg xml,” width=”750″>

Click on “Create Load Balancer” to create your first load balancer.

<img alt="Create Load Balancer" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.02_.55_PM_.png617ac70352bc1.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="417" loading="lazy" src="data:image/svg xml,” width=”750″>

To create an Application Load Balancer, select “Application Load Balancer” and click on create. There are two more types of load balancers available in AWS, we are not going to discuss them in this article.

<img alt="Select balancer type" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.03_.02_PM_.png617ac70391dc2.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="416" loading="lazy" src="data:image/svg xml,” width=”750″>

Type a Name for the load balancer, keep the Scheme as “Internet-facing” so that the load balancer routes requests from clients over the Internet to targets. Keep the other settings unchanged and click on “Next: Configure Security Settings”. 

<img alt="LB name" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.04_.00_PM_.png617ac703ca5b3.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="418" loading="lazy" src="data:image/svg xml,” width=”750″>

Scroll down and select at least two Availability Zones from your VPC. I have selected three of them here. Click on “Next: Configure Security Settings” to proceed.

<img alt="Load Balancer protocol" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.04_.13_PM_.png617ac7040dcef.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="417" loading="lazy" src="data:image/svg xml,” width=”750″>

Since we have used HTTP and not HTTPS in Listener, in the previous step, we see this warning. For the test environment, we can ignore this but for the production environment, it is recommended to use HTTPS. To proceed with HTTP click on “Next: Configure Security Groups”.

<img alt="Security settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.04_.25_PM_.png617ac7044b96b.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="418" loading="lazy" src="data:image/svg xml,” width=”750″>

Select “Create a new security group”, this will contain the rule that allows traffic to the port that we selected for our load balancer.  If you already have your security group in place, you can choose it by clicking on “Select and existing group”. “Click on “Next: Configure Routing”.

<img alt="Configure security group" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.04_.49_PM_.png617ac70480f48.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="417" loading="lazy" src="data:image/svg xml,” width=”750″>

Here, specify a name for the target group and keep the rest configuration as is and click on Choose “Next: Register Targets”. Make sure the name here is unique and there is no other target group in this region with the same name.

<img alt="Configure routing" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.05_.13_PM_.png617ac704bb264.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="417" loading="lazy" src="data:image/svg xml,” width=”750″>

Here, select one or more instances having apache running on port 80 from the list available and click on “Add to registered”. Click on “Next: Review” to proceed.

<img alt="Register targets" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.11_.05_PM_.png617ac70513418.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="417" loading="lazy" src="data:image/svg xml,” width=”750″>

Review all the configuration here and click on “Create”.

<img alt="Review settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.11_.14_PM_.png617ac7054a178.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="418" loading="lazy" src="data:image/svg xml,” width=”750″>

Click on Close to close the window and return to the main window of Load Balancer.

<img alt="Load balancer created successfully" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.11_.29_PM_.png617ac7058e37f.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="419" loading="lazy" src="data:image/svg xml,” width=”750″>

Once the State changes to “active”, we can verify that our targets have passed the initial health check and then test that the load balancer is sending traffic to the instances registered. Copy the DNS name from the description tab. This step may take a few mins so wiat till then.

<img alt="List of load balancers" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.18_.11_PM_.png617ac705b186b.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="420" loading="lazy" src="data:image/svg xml,” width=”750″>

Hit the URL you copied in the browser and you can see that the load balancer is sending traffic to the instances with Apache on them.

<img alt="test page" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/Screenshot_2020-02-14_at_11.18_.20_PM_.png617ac705f199f.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="438" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

In this article, we saw the steps to create an Application Load Balancer and register instances to the target group.