Working With Elastic Load Balancing
Working With Elastic Load Balancing
Working With Elastic Load Balancing
Load Balancing
55 minutes8 Credits
Rate Lab
Lab Overview
This lab introduces the concept of Elastic Load Balancing. In this lab you will
use Elastic Load Balancing to load balance traffic across multiple Amazon
Elastic Compute Cloud (EC2) instances in a single Availability Zone. You will
deploy a simple application on multiple Amazon EC2 instances and observe
load balancing by viewing the application in your browser.
First, you will launch a pair of instances, bootstrap them to install web servers
and content, and then access the instances independently using Amazon EC2
DNS records. Next, you will set up Elastic Load Balancing, add your instances
to the load balancer, and then access the DNS record again to watch your
requests load balance between servers. Finally, you will view Elastic Load
Balancing metrics in Amazon CloudWatch.
Topics covered
This lab will take you through:
Achieve higher levels of fault tolerance for your applications by using Elastic
Load Balancing to automatically route traffic across multiple instances and
multiple Availability Zones. Elastic Load Balancing ensures that only healthy
Amazon EC2 instances receive traffic by detecting unhealthy instances and
rerouting traffic across the remaining healthy instances. If all of your Amazon
EC2 instances in one Availability Zone are unhealthy, and you have set up
Amazon EC2 instances in multiple Availability Zones, Elastic Load Balancing
will route traffic to your healthy Amazon EC2 instances in those other zones.
Elastic Load Balancing works with Amazon Virtual Private Cloud (VPC) to
provide robust networking and security features. You can create an internal
(non-Internet facing) load balancer to route traffic using private IP addresses
within your virtual network. You can implement a multi-tiered architecture
using internal and Internet-facing load balancers to route traffic between
application tiers. With this multi-tier architecture, your application infrastructure
can use private IP addresses and security groups, allowing you to expose only
the Internet-facing tier with public IP addresses.
This lab guide explains basic concepts of Elastic Load Balancing in a step-by-
step fashion. However, it can only give a brief overview of Elastic Load
Balancing concepts. For further information,
see http://aws.amazon.com/elasticloadbalancing/.
Start Lab
1. At the top of your screen, launch your lab by clicking Start Lab
If you are prompted for a token, use the one distributed to you (or credits you
have purchased).
A status bar shows the progress of the lab environment creation process. The
AWS Management Console is accessible during lab resource creation, but
your AWS resources may not be fully available until the process is complete.
3. On the Services menu, click EC2.
4. Click Launch Instance
5. In the row for the Amazon Linux 2 AMI, click Select
The t2.micro instance type, which is the lowest-cost option, should be
automatically selected.
6. Click Next: Configure Instance Details then configure:
Number of instances:
Network: Lab VPC
7. Scroll to the bottom of the screen, then expand Advanced Details.
8. Enter the following into User data:
#!/bin/sh
yum -y install httpd php
chkconfig httpd on
systemctl start httpd.service
cd /var/www/html
wget https://s3-us-west-2.amazonaws.com/us-west-2-aws-training/awsu-
spl/spl-03/scripts/examplefiles-elb.zip
unzip examplefiles-elb.zip
This will allow you to bootstrap your instance. It will install Apache and PHP
and sample code (PHP scripts) needed for this lab when the instance is
created and launched. User data provides a mechanism to pass data or a
script to the Amazon metadata service, which instances can access at launch
time.
Tip If you type this text instead of copying it, press SHIFT+ENTER to create
new lines in the text box.
9. Click Next: Add Storage
You will use the default storage device configuration.
Instance State: running
Status Checks: 2/2 checks passed
This indicates that you instance is now fully available for us.
This may take a few minutes. You can refresh the status of your instances by
clicking the refresh icon.
Task 2: Connect to Each Web Server
In this task, you will:
Retrieve the public DNS entries for both of your EC2 instances
Point your browser at each DNS entry to access your instances web
server
All Amazon EC2 instances are assigned two IP addresses at launch: a private
IP address (RFC 1918) and a public IP address that are directly mapped to
each other through Network Address Translation (NAT). Private IP addresses
are only reachable from within the Amazon EC2 network. Public addresses
are reachable from the Internet.
Amazon EC2 also provides an internal DNS name and a public DNS
name that map to the private and public IP addresses, respectively. The
internal DNS name can only be resolved within Amazon EC2. The public DNS
name resolves to the public IP address outside the Amazon EC2 network and
to the private IP address within the Amazon EC2 network.
18. Select your first Amazon EC2 instance.
19. Copy the Public DNS (IPv4) value to your Clipboard.
It will look something like ec2-54-84-236-205.compute-1.amazonaws.com.
20. Open a new browser window, paste the Public DNS value into the
address bar, and press ENTER. Your browser will display a screen like
this:
This is the web page returned by the PHP script that was installed when the
instance was started. It is a simple script that interrogates the metadata
service on each machine and returns the instance ID and the name of the
Availability Zone in which the instance is running.
21. Repeat the previous two steps for your second instance.
Notice that each machine displays a different instance ID. This will help you
identify which instance is processing your request when you put a load
balancer in front of them.
If you see an error instead of the instance ID and Availability Zone when you
access the instances from the browser, try again after a couple of minutes. It’s
possible that the bootstrapping script is still running and has not yet completed
installing and starting the web server and PHP application. If errors persist,
verify that you entered the bootstrap script correctly when you launched your
instances and that the security group has port 80 open.
33. Click Close
It will take a couple of minutes to start up the load balancer, attach your web
servers, and pass the health checks.
Load balancers can span Availability Zones, and they also scale elastically as
needed to handle demand. Therefore, you should always access a load
balancer by DNS hostname, and not by IP address. A load balancer may have
multiple IP addresses associated with its DNS hostname.
Amazon CloudWatch provides monitoring for AWS cloud resources and the
applications customers run on AWS. Developers and system administrators
can use it to collect and track metrics, gain insight, and react immediately to
keep their applications and businesses running smoothly. CloudWatch
monitors AWS resources such as Amazon EC2 and Amazon Relational
Database Service (RDS) DB instances and can also monitor custom metrics
generated by your applications and services. With CloudWatch, you gain
system-wide visibility into resource use, application performance, and
operational health.
End Lab
Follow these steps to close the console, end your lab, and evaluate the
experience.
Conclusion
Congratulations! You now have successfully:
Launched a multiple server web farm on Amazon EC2
Used bootstrapping techniques to configure Linux instances with
Apache, PHP, and a simple PHP application
Created and configured a load balancer that sits in front of your Amazon
EC2 web server instances
Viewed Amazon CloudWatch metrics for the load balancer
Additional Resources
Elastic Load Balancing and Elastic Load Balancing pricing
AWS Training and Certification
For feedback, suggestions, or corrections, please email: aws-course-
feedback@amazon.com