Use Application Load Balancers for Web Servers

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

Load balancing automatically distributes your incoming traffic across multiple targets, such as EC2 instances, containers, and IP addresses, in one or more Availability Zones. In this lab, we configure an Application Load Balancer to distribute network traffic to 2 EC2 instances. We then enable stickiness, so that once a server is contacted, the user is always sent to that server. This ensures our legacy application continues to work despite not supporting distributed logins. By the end of this lab, the user will understand how to create an Application Load Balancer and enable sticky sessions.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Observe the Provided EC2 Website and Create a Second Server

Observe the website configured on the existing EC2 server. Using the bootstrap script provided, boot another EC2 server.

Create an Application Load Balancer

Create a load balancer called LegacyApplication with a target group called ‘TargetGroup’, add the 2 EC2 servers as targets, and observe how the load balancing works in your web browser.

Enable Sticky Sessions

Configure the load balancer to use stickiness, and observe how the load balancer now only directs the user to a single EC2 server (as expected).

Additional Resources

Log in to the live AWS environment using the credentials provided. Use an incognito or private browser window to ensure you're using the lab account rather than your own.

Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

Here is the EC2 bootstrap script you'll need for the lab:

#!/bin/bash
sudo apt-get update -y
sudo apt-get install apache2 unzip -y
echo '<html><center><body bgcolor="black" text="#39ff14" style="font-family: Arial"><h1>Load Balancer Demo</h1><h3>Availability Zone: ' > /var/www/html/index.html
curl http://169.254.169.254/latest/meta-data/placement/availability-zone >> /var/www/html/index.html
echo '</h3> <h3>Instance Id: ' >> /var/www/html/index.html
curl http://169.254.169.254/latest/meta-data/instance-id >> /var/www/html/index.html
echo '</h3> <h3>Public IP: ' >> /var/www/html/index.html
curl http://169.254.169.254/latest/meta-data/public-ipv4 >> /var/www/html/index.html
echo '</h3> <h3>Local IP: ' >> /var/www/html/index.html
curl http://169.254.169.254/latest/meta-data/local-ipv4 >> /var/www/html/index.html
echo '</h3></html> ' >> /var/www/html/index.html  

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?