Creating and Configuring a Network Load Balancer in AWS

1.75 hours
  • 5 Learning Objectives

About this Hands-on Lab

In the learning activity, the student will use what they have learned about Network Load Balancers to deploy and configure a simple web application with traffic load balanced between two web servers. The student will walk through preparing the AWS environment for the Network Load Balancer (configuring subnets, network ACL, and EC2 instances). When the preparation is complete, the student will create and configure a Network Load Balancer. After configuration of the load balancer, the student will work from the CLI to run a small test on the load balancer and view the results in the CloudWatch *Monitoring* metrics.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create and Configure a Subnet
  • From the AWS Management Console, navigate to the VPC Management Console
  • Select Subnets
  • You will see one subnet already created. To create a second subnet, click Create subnet
  • Select the VPC provided
  • Name the subnet Public B
  • Select the us-east-1b Availability Zone
  • Enter a CIDR block which will not overlap with the CIDR block of the existing subnet
  • Create the Public B subnet
  • Navigate to the route table for the new Public B subnet
  • Update the routes on the route table to have a route for 0.0.0.0/0 pointing to the internet gateway of the VPC
  • Update the explicit subnet associations to use the new Public B subnet
Edit the Network ACL
  • Select Subnets
  • Select the Public B subnet
  • Under the Network ACL tab, click on the network ACL link
  • Edit the inbound rules to permit only ports 80, 443, 22, and 1024 through 65535
  • Click Save changes
Create EC2 Instances
  • Navigate to the EC2 Management Console

  • Click on Instances

  • Click on Launch instances

  • Configure a new instance called Web-A with the following values:

    • AMI: Amazon Linux 2
    • Instance Type: t2.micro
    • Subnet: us-east-1a
    • Auto-assign Public IP: Enable
    • User data: use the Web-A script provided with the lab
    • Volume Size: 8 GB
    • Security Group: use the provided security group (not the default security group)
  • Configure a new instance called Web-B with the following values:

    • AMI: Amazon Linux 2
    • Instance Type: t2.micro
    • Subnet: us-east-1b
    • Auto-assign Public IP: Enable
    • User data: use the Web-B script provided with the lab
    • Volume Size: 8 GB
    • Security Group: use the provided security group (not the default security group)
Create and Configure a Network Load Balancer
  • Click on Load Balancers

  • Click Create Load Balancer

  • Select the Network Load Balancer option and, in the Basic Configuration section, set the following values:

    • Load Balancer name: NLB4LAB
    • Scheme: internet-facing
  • In the Network mapping section, use the provided VPC and select both us-east-1a and us-east-1b

  • In the Listeners and routing section, click Create target group

  • Use the following values for the new target group:

    • Choose a target type: instances
    • Target group name: nlbTargets
    • Protocol: TCP
    • Port: 80
    • Health check protocol: TCP
  • Register both the Web-A and Web-B instances to the nlbTargets target group

  • Back on the Create Network Load Balancer page, in the Listeners and Routing section, select the nlbTargets target group

  • Click Create Load Balancer

Test and Monitor the Network Load Balancer
  • Click Load Balancers and select the NLB4LAB load balancer
  • From the Description tab, copy the DNS name of the load balancer and view the web page in a new browser tab
  • In a second tab, navigate to the EC2 console and click on Instances
  • Select the AdminInstance server and, from the Details tab, copy the public IP address
  • In the terminal of your choice, SSH into the AdminInstance server
  • Run the following command from the AdminInstance server:
    while true; do curl <LOAD BALANCER DNS NAME>; done
  • Let the command run for multiple iterations and then hit Ctrl+C to break out of the loop
  • Back on the Load Balancers page, click the Monitoring tab and review the CloudWatch metrics for network activity

Additional Resources

  • Log in to the live environment with the cloud_user credentials provided, but do NOT attempt to SSH or log into the Cloud Server until the last objective.
  • Make sure you are using us-east-1 as your Region throughout the learning activity.
  • Below is the user data script for the Web-A instance:

    #!/bin/bash
    
    yum update -y && yum -y install httpd && systemctl enable httpd && systemctl start httpd
    
    usermod -a -G apache ec2-user 
    chown -R ec2-user:apache /var/www
    chmod 2775 /var/www
    find /var/www -type d -exec chmod 2775 {} ;
    find /var/www -type f -exec chmod 0664 {} ;
    echo "Request Handled by: Web-A" >> /var/www/html/index.html
    • Below is the user data script for the Web-B instance:
      
      #!/bin/bash

    yum update -y && yum -y install httpd && systemctl enable httpd && systemctl start httpd

    usermod -a -G apache ec2-user chown -R ec2-user:apache /var/www chmod 2775 /var/www find /var/www -type d -exec chmod 2775 {} ; find /var/www -type f -exec chmod 0664 {} ; echo "Request Handled by: Web-B" >> /var/www/html/index.html

  • At the end of the learning activity, you will test the Network Load Balancer by sending a large amount of requests to it in a short time period. The following command will create an endless loop which continually makes a request to the Network Load Balancer:
    while true; do curl <LOAD BALANCER DNS NAME>; done

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?