☰

AWS ELB: What Is Elastic Load Balancer & How It Works

Elastic Load Balancer

Elastic Load Balancing is an Amazon Web Service which is able to distribute workload to many targets such as EC2 instances. It ensures that no one server is overloaded. This tutorial will explain what an elastic load balancer is. It also includes information on what to prepare for as well as explaining, in steps, how to configure and create an Application Load Balancer. Further, it will show you how to configure a target group and health checks for AWS Elastic Load Balancing.

⚡ QUICK ANSWER

ELB can automatically distribute workloads to a number of targets (such as EC2 instances in various Availability Zones). It also checks the health of these targets, and will only distribute workload to those that are healthy. There are various types of AWS load balancer, of which Application Load Balancers are used to distribute workload for HTTP and HTTPS.

If you are looking for the best place to obtain information about the Elastic Load Balancer, or are keen to undertake a high level Certification Course at India’s Leading AWS training Institute, then you have come to the right place!

Simply follow each tutorial from India’s Leading Best AWS training Institute and you will gain a thorough understanding of Elastic Load Balancing and become a Pro AWS Developer.

In this article, you will learn:

  • What Is Elastic Load Balancer in AWS?
  • Before You Configure Load Balancer
  • How to Create Application Load Balancer in AWS Step by Step
  • How to Configure Target Group and Health Checks in AWS ELB
  • Register Targets, Test and Delete Your Load Balancer

What Is Elastic Load Balancer in AWS?

There are three types of load balancer available in AWS. Within this tutorial we will be configuring an Application Load Balancer.

In order to configure an Application Load Balancer

Access the Amazon EC2 console ( https://console.aws.amazon.com/ec2/ ).

Using the navigation bar, select a region. This must match that which you specified for your EC2 instances.

From the navigation pane, under LOAD BALANCING, click Load Balancers.

Click Create Load Balancer.

Select Create for Application Load Balancer.

Before You Configure Load Balancer

If you are new to AWS, first create a free AWS account so you can follow the steps in this tutorial.You need to determine which two Availability Zones you wish to deploy your EC2 instances. Then configure your virtual private cloud (VPC) Network. Within each of these zones, ensure that you have at least one public subnet. These are used to configure your load balancer so that it can distribute workload to your EC2 instances. You can also deploy EC2 instances within further subnets within these Availability Zones.

EC2 User Data

It is important that an Apache HTTP server is installed onto our AWS EC2 instance.

We will now write some user data code.

This will be executed on the instance upon its initial boot up.

First, let us delete our existing instance and then re-deploy it.

Again deploying our instance, however this time utilising User Data. Then, we will test our new instance within our browser.

#!/bin/bash

sudo su

yum update -y

yum install -y httpd.x86_64

systemctl start httpd.service

systemctl enable httpd.service

EC2_AVAIL_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)

echo “Hello World from $(hostname -f) in AZ $EC2_AVAIL_ZONE

“>/var/www/html/index.html

You must include code within the description field at step four when deploying your EC2 instance in order to recognise your instance. See for example, below, step four of the deployment process:

Elastic Load Balancer

Below I have deployed two EC2 instances, one within availability zone ap-south-1a, and another within availability zone ap-south-1b:

Elastic Load Balancer

Ensure that you deploy at least one EC2 instance within each Availability Zone in your region. Additionally, install a web server (for example, Apache or Internet Information Services (IIS)) onto each of these instances. Ensure that their security groups allow HTTP traffic on port 80.

Within this tutorial, deploy two EC2 instances within Availability Zones ap-south-1a and

How to Create Application Load Balancer in AWS Step by Step

Step 1: Select a Load Balancer Type

As stated above, there are three types of load balancer available on AWS. Here, we will be creating an Application Load Balancer.

To create an Application Load Balancer

Access the Amazon EC2 console ( https://console.aws.amazon.com/ec2/ ).

Using the navigation bar, select a region. This should be the same region as that selected for your EC2 instances.

From the navigation pane, under LOAD BALANCING, click Load Balancers.

Click Create Load Balancer.

Select Create for Application Load Balancer.

Step 2: Configure Your Load Balancer & Listener

Carry out the following on the Configure Load Balancer screen.

To configure your load balancer and listener

Enter a name for your Load Balancer.

Your Application Load Balancer name must be unique compared to other Application Load Balancers and Network Load Balancers within the region. Furthermore, it can be up to 32 characters long and can include alphanumeric characters and hyphens. However, it cannot begin or end with a hyphen. Likewise, it should not begin with the string ‘internal-’.

Maintain the default values for Scheme& IP address type.

Leave the default listener (which listens for HTTP traffic on port 80).

For the Availability Zones, select the VPC which was used for your EC2 instances. For each Availability Zone within which you deployed your EC2 instances, choose availability zone ap-south-1a and then select the public subnet for this Availability Zone, ap-south-1b.

Elastic Load Balancer

Click Next: Configure Security Settings.

As we are not configuring an HTTPS listener within this tutorial, select Next: Configure Security Groups.

Step 3: Configure a Security Group for Your Load Balancer

A security group must be configured so that communication can occur between your Load Balancer and your registered targets (both for the listener and health check ports). The console can automatically generate a security group for your Load Balancer including suitable rules for the relevant protocols and ports. Alternatively, you may manually create and select a security group. Below, we will show you how to allow the console to generate a security group for your Load Balancer.

To configure a security group for your load balancer

Click Create a new security group.

Enter, or leave as default, a name and description. The newly created security group will include a rule allowing traffic to reach your Load Balancer on the listener port you selected within the Configure Load Balancer

Elastic Load Balancer screen. Select Next: Configure Routing.

Elastic Load Balancer

How to Configure Target Group and Health Checks in AWS ELB

Step 4: To Configure Your Target Group

A target group is used to direct workload. The default rule for your listener will dispatch workload to targets which are registered within your target group. Your Load Balancer assesses the health of the targets within your target group according to the health check configuration for this group. Complete the below on the Configure Routing screen.

To configure your target group

Maintain the default value for Target group – New target group.

Enter a name for your new target group.

Also retain the default values for Target type (Instance), Protocol (HTTP) and Port (80).

Maintain the default Health checks configuration.

Click Next: Register Targets.

Register Targets, Test and Delete Your Load Balancer

Step 5: Register Targets with Your Target Group

Carry out the below actions on the Register Targets screen.

To register your instances with the target group

Select one or more instances.

  1. Maintain the default port (80) and click Add to add them.

Having made your selections, click Next: Review.

Step 6: Create & Test Your Load Balancer

Verify your choices prior to creating your Load Balancer. After doing so, confirm that your Load Balancer is dispatching workload to your EC2 instances.

To create & test your load balancer

Click Create on the Review screen.

Upon receiving confirmation that your Load Balancer has been successfully created, click Close.

Following successful creation of a Load Balancer it will take a short period of time for it to become active once provisioning has been completed.

Within the navigation pane, under LOAD BALANCING, click Target Groups.

Select your new target group.

  1. Within the Targets tab, confirm that your instances are active. If an instance has a status of initial this is likely to be because it is still being registered or because it has not yet met the required minimum number of health checks and is therefore not deemed to be healthy.

As soon as at least one of your instances is deemed to be healthy, you can test your Load Balancer.

Within the navigation pane, under LOAD BALANCING, click Load Balancers.

Select your new Load Balancer.

Within the Description tab, copy the Load Balancer’s DNS name (for example, my-load-balancer-1234567890.us-west-2.elb.amazonaws.com). Paste this into the address box of an Internet connected browser. Provided that everything is functioning correctly, the browser will then show you the default page for your server.

Refreshing the browser will demonstrate that it is accessing the ap-south-1b Availability Zone.

Step 7: Delete Your Load Balancer (Optional)

As soon as your Load Balancer is active, you are charged, per hour or part-hour, for its continued use. Therefore, if you no longer require a Load Balancer, you can delete it. Immediately upon deletion, you will no longer be charged for it. Importantly, deletion of a Load Balancer does not impact the targets which were registered to it. Therefore, for example, your EC2 instances will still remain active.

To delete your load balancer

Access the Amazon EC2 console ( https://console.aws.amazon.com/ec2/ ).

Within the navigation pane, under LOAD BALANCING, click Load Balancers.

Select the checkbox next to your Load Balancer. Then, from the Actions menu, click Delete.

When asked to confirm deletion, click Yes, Delete.

Finally, don’t hesitate to seek assistance where needed!

Conclusion

An Elastic Load Balancer distributes workload to a number of healthy servers located in separate Availability Zones. Consequently, even if one of these servers malfunctions, your application will still function. Throughout this tutorial we have shown you how to prepare for deploying a Load Balancer, how to deploy EC2 instances incorporating User Data and how to configure a Load Balancer, together with how to configure a Target Group and health checks. We have furthermore explained how to test and delete your configuration so that you do not continue to incur charges. As more and more applications are deployed within the cloud, the ability to design robust methods of distributing workload will continue to be key for those working with AWS.To strengthen these skills with guided practice, explore Prwatech’s AWS online training course. 

Frequently Asked Questions

  1. What is an elastic load balancer in AWS?

Elastic Load Balancing is an AWS service which can automatically distribute workload to a variety of targets (for example, EC2 instances, containers and IP addresses). It can also span multiple Availability Zones and will only send workload to healthy targets. This therefore increases an application’s availability and enables it to adapt to fluctuating workloads.

  1. How does ELB work?

A Load Balancer receives incoming traffic through a listener, such as HTTP on port 80. It applies routing rules and forwards requests to registered targets within a target group. It also performs regular health checks and temporarily removes unresponsive targets from rotation until they pass the checks.

  1. What is an Application Load Balancer?

Application Load Balancers are a type of ELB, which operate at an application level. They can manage workload for both HTTP and HTTPS. Furthermore, they can direct workload to different target groups depending on routing rules. For this reason, they are frequently used for web applications. Within this tutorial, we have utilised this type of Load Balancer.

  1. How many types of load balancers does AWS offer?

As previously mentioned, AWS provides three Load Balancer types. Within this tutorial we have configured an Application Load Balancer. Consider which type is most appropriate for your application and the degree of control that you would like to have over routing.

  1. How to create an application load balancer in AWS step by step?

Access the EC2 console. From here, navigate to Load Balancers and click Create Load Balancer. Then, select Application Load Balancer. Enter a name for your Load Balancer. Retain the default port 80 listener. Subsequently, select your VPC and subnets. Configure a security group. Then, define a target group and register your instances. Finally, review and create your Load Balancer.

  1. How to configure target groups and health checks in AWS ELB?

On the Configure Routing screen, retain the New target group. Enter a name for your target group. Again, maintain the default values for Target type (Instance), Protocol (HTTP) and Port (80). Likewise, do not amend the Health checks configuration. Then, register your EC2 instances so that your Load Balancer can assess and utilise them.

  1. Why do I need EC2 instances in two Availability Zones?

Deploying instances across two Availability Zones helps maintain workload distribution if one zone experiences an issue. Each zone also requires a public subnet to allow the Load Balancer to distribute traffic. In this tutorial, we use the ap-south-1a and ap-south-1b Availability Zones to demonstrate how traffic switches between them.

  1. How do I know my load balancer is working?

Review the Targets tab for your target group and ensure that at least one of your instances has a healthy status. Then, copy and paste the Load Balancer’s DNS name from its details into the address box of an Internet connected browser. Upon refreshing the browser, you should observe that it is receiving responses from different Availability Zones.

  1. Does an AWS load balancer cost money?

Yes. AWS starts charging you hourly (or for any part of an hour) as soon as your Load Balancer becomes active. When you no longer require a Load Balancer, you can delete it from the EC2 console by clicking Actions, Delete. AWS stops charging you as soon as you delete the Load Balancer. However, deleting it does not terminate the EC2 instances registered with it.

Popular Tags:

Elastic Load Balancer