Lesson 3 of 4 Compute Services

Making Applications Elastic with Auto Scaling and Load Balancing

This lesson explains how Amazon EC2 Auto Scaling and Elastic Load Balancing work together to make applications elastic, fault tolerant and highly available.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how Amazon EC2 Auto Scaling adjusts the number of instances to demand.
  • Describe how Elastic Load Balancing spreads traffic across healthy targets.
  • Explain how the two services together keep an application available when an Availability Zone fails.

Amazon EC2 Auto Scaling

Amazon EC2 Auto Scaling adjusts the number of instances to match demand. The following list describes how it works.

  • Automatically launches or terminates instances to keep the right number running, between a minimum, maximum and desired capacity.
  • Scales on demand (e.g. average CPU at 50%), on a schedule (e.g. business hours) or by prediction, giving elasticity and saving money.
  • Runs health checks and replaces unhealthy instances, improving fault tolerance.
True or false

EC2 Auto Scaling

Exam skills 3.3.4

Check how EC2 Auto Scaling works.

Log in to try this activity Interactive activities are free with an account.

Elastic Load Balancing (ELB)

Elastic Load Balancing spreads incoming traffic across several targets, such as EC2 instances, containers, IP addresses or Lambda functions, in several Availability Zones. It sends traffic only to targets that pass health checks, so the application keeps working when one fails. There are three types. An Application Load Balancer understands web traffic (HTTP and HTTPS) and can route requests by their URL path or host name, which suits web applications and microservices. A Network Load Balancer handles TCP and UDP traffic with extreme performance and static IP addresses. A Gateway Load Balancer sends traffic through third-party virtual appliances, such as firewalls. The following table summarises the types.

Load balancerLayerUse for
Application Load Balancer7 (HTTP, HTTPS)Web apps and microservices; routes by URL path or host name
Network Load Balancer4 (TCP, UDP)Extreme performance and static IP addresses
Gateway Load Balancer3Third-party virtual appliances such as firewalls
Sort into groups

Which load balancer?

Exam skills 3.3.5

Choose the load balancer type for each need.

Log in to try this activity Interactive activities are free with an account.

A highly available architecture

An Application Load Balancer in front of an Auto Scaling group spanning several Availability Zones. If an instance, or a whole AZ, fails, traffic flows to healthy instances and Auto Scaling replaces the lost capacity.

The following diagram shows a load balancer in front of an Auto Scaling group across three AZs.

A highly available architecture. An Application Load Balancer spreads requests across instances in an Auto Scaling group that spans several Availability Zones. If an instance or a whole AZ fails, the load balancer sends traffic only to healthy instances, and Auto Scaling launches replacements. When demand grows, Auto Scaling adds instances, and it removes them when demand falls.
Load balancing gives availability; Auto Scaling gives elasticity and self-healing.
Worked example

A website that heals and scales itself

A news site runs on EC2 instances in an Auto Scaling group across three Availability Zones, behind an Application Load Balancer. The group is set to a minimum of 3, desired 3 and maximum 15 instances, with a policy to keep average CPU around 50%. Here is what happens on a big news day:

TimeEventWhat AWS does
09:00Normal traffic3 instances, one per AZ; the load balancer spreads requests
11:30Breaking news; CPU rises to 85%Auto Scaling launches instances up to 12; the load balancer starts sending them traffic
13:00One instance crashesHealth checks fail; the load balancer stops sending it traffic; Auto Scaling replaces it
18:00Traffic fallsAuto Scaling removes instances back to 3, so the company stops paying for them

Load balancing provides availability and spreads the load; Auto Scaling provides elasticity and replaces failed instances. Together across several AZs they make the site highly available and cost effective.

Check yourself

What does Elastic Load Balancing do?

Show answer

It spreads incoming traffic across healthy targets, such as EC2 instances in several Availability Zones.

Exam Tips

Remember for the exam

  • To add or remove instances automatically with demand, use EC2 Auto Scaling.
  • Unhealthy instances are replaced automatically by Auto Scaling health checks.
  • To distribute traffic across instances and Availability Zones, use Elastic Load Balancing.
  • Web traffic routed by URL path calls for an Application Load Balancer.
  • Very high-performance TCP or UDP traffic calls for a Network Load Balancer.
  • High availability comes from a load balancer and Auto Scaling across several Availability Zones.