Skip to main content

Create a Classic Elastic Load Balancer (ELB)

Hands-On Lab


Photo of Christophe Limpalair

Christophe Limpalair

VP of Growth in Marketing





A load balancer distributes incoming application traffic across multiple EC2 instances in multiple Availability Zones. This increases the fault tolerance of your applications. Elastic Load Balancing detects unhealthy instances and routes traffic only to healthy instances. Your load balancer serves as a single point of contact for clients. This increases the availability of your application. You can add and remove instances from your load balancer as your needs change, without disrupting the overall flow of requests to your application. Elastic Load Balancing scales your load balancer as traffic to your application changes over time. Elastic Load Balancing can scale to the vast majority of workloads automatically. In this lab, we are going to cover the following objectives: - Creating a classic load balancer - Adding subnets to load balancer - Enabling cross-zone load balancing - Attaching the load balancer to an Auto Scaling group

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.


In this lab, we are going to cover the following objectives:

  • Creating a classic ELB
  • Adding subnets to an ELB
  • Enabling cross-zone load balancing
  • Attaching the load balancer to an Auto Scaling group

Before we begin, ensure that you are in the N. Virginia region. You can view and change your current region in the top right of the AWS website (beside the Support link in the black navigation bar).

Create a Classic Elastic Load Balancer (ELB)

We will begin by creating a new load balancer:

  • Navigate to the Load Balancers page in the EC2 section of AWS.
  • Click the Create Load Balancer button in the top left.
  • Select the Classic Load Balancer option and click Continue.
  • For the Load Balancer Name setting, we will type an appropriate name of classic-load-balancer.
  • In the Listener Configuration section, ensure that the Load Balancer Protocol and Instance Protocol settings are both set to HTTP on port 80.

Add Subnets

Notice that we've left the "Create an internal load balancer" option unchecked, which means we are creating an Internet-facing ELB. In the Select Subnets section of this page, you'll notice that we have 2 private subnets and 2 public subnets. Since an Internet-facing ELB requires an Internet Gateway to function properly, we will need to select the public subnets.

  • Click the + icon on listings for both public subnets. This will add them to the "Selected Subnets" list below.
  • Click the Next: Assign Security Groups button at the bottom of the page.

Create Security Group

We will create a new security group to allow HTTP and HTTPS traffic:

  • With the Select an existing security group selected, you will see a default security group and a custom one created for your lab. Click the Copy to new link to the right of the custom security group.
  • Remove the ping protocol listing (All ICMP type) and the SSH listing because we don't need them for the load balancer.
  • For the Security group name and Description settings, type classic-loadbalancer-security-group.
  • The other default settings are fine, so click the Next: Configure Security Settings button below.

We don't need to make any changes to the security settings, so we can immediately click the Next: Configure Health Check button to skip it.

Configure Health Check

A health check is designed to ping instances, identify unresponsive ones, and stop routing traffic to the unresponsive instances. If the health check determines a particular instance is not responsive, it routes traffic to different instances for a pre-determined amount of time to give the instance a chance to recover. This improves the availability of your application since users will not be waiting on an unresponsive instance, instead being routed to one that's working..

Let's configure our health check:

  • Set the Ping Protocol to TCP.
  • Leave the default Ping Port setting of port 80.
  • Set the Response Timeout to 5 seconds.
  • Set the Interval to 30 seconds.
  • The Unhealthy Threshold setting defines the consecutive ping failures required to consider an instance "unhealthy." Let's choose 2 here as well.
  • Similarly, the Healthy Threshold setting allows us to define the number of consecutively successful pings required to consider an instance "healthy." We will choose 2 for this lab.
  • Click the Next: Add EC2 Instnaces button to move on.

Enable Cross-Zone Load Balancing

We could select the instances listed here to attach them to the load balancer. Since these instances have been launched in an Auto Scaling group, we will leave these unchecked and later attach the group instead. This is best practice.

Ensure that the Enable Cross-Zone Load Balancing setting has been checked on this page. This option will evenly distribute traffic among the two different availability zones for high availability.

Be sure that that Enable Connection Draining option is checked. This option keeps existing connections to instances that are being marked as unhealthy. This lets unfinished requests be completed on instances that are being de-registered. After this set time of 300 seconds, it closes the connections with that instance. We are now finished customizing the settings for our new ELB.

Finish the Setup

We have changed all the initial settings required to set up our ELB and are ready to create it. We will have to navigate through a few more steps before we can finish. Leave the rest of the settings as their defaults.

  • Click Next: Add Tags.
  • Click Review and Create.
  • Finally, click the Create button.

AWS will create a new classic ELB with the settings we've defined so far.

Attach the Auto Scaling Group

Navigate back to the Load Balancers page. Select the load balancer that we just created (named classic-load-balancer). Click the Instances tab in the information pane at the bottom of the page. Notice the lack of attached instances. We can fix this by attaching our Auto Scaling group.

  • Click the Auto Scaling Groups link under the Auto Scaling section in the navigation list to the left of the page.
  • Click the Edit button under the details.
  • In the Load Balancers setting, choose the classic-load-balancer that we just created.
  • Click the Save button.

If we go back to the Load Balancer section, you will see the instances begin to populate as the health checks determine the statuses of each instance.

Checking Our Work

Go back to the Description tab for the load balancer. Copy the DNS Name (copy everything but the (A Record) part) and paste it into a new browser tab. You will see the Amazon Linux AMI Test Page.