Lesson 1 of 4 Elastic Load Balancing

Routing HTTP Traffic with an Application Load Balancer

This lesson explains the Application Load Balancer, the default for HTTP and HTTPS applications, as part of choosing the right load balancer, one of the most frequently tested decisions in the exam.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose between the types of load balancer.
  • Explain how ALB listener rules route requests.
  • Choose between internet-facing and internal schemes.
  • Describe how access logs and metrics monitor an ALB.

Choosing a load balancer

Elastic Load Balancing offers three types of load balancer, which work at different network layers. An Application Load Balancer (ALB) works at layer 7 and understands HTTP, HTTPS, HTTP/2, gRPC and WebSockets. It can route by the content of each request, authenticate users and use AWS WAF. Targets see the client's address in the X-Forwarded-For header, because the ALB opens its own connection to them.

A Network Load Balancer (NLB) works at layer 4, forwarding TCP, UDP and TLS connections with very high throughput and low latency. It provides static IP addresses, preserves the client's IP address and can expose a service through AWS PrivateLink. A Gateway Load Balancer (GWLB) works at layer 3, sending IP packets, encapsulated with the GENEVE protocol, to fleets of security appliances, such as firewalls, so they can inspect traffic transparently. The following table summarises the three types.

Application (ALB)
Layer7: HTTP, HTTPS, HTTP/2, gRPC, WebSockets
StrengthsContent-based routing, authentication, WAF
Client IPX-Forwarded-For header
Network (NLB)
Layer4: TCP, UDP, TLS
StrengthsStatic IPs, extreme performance, PrivateLink
Client IPPreserved
Gateway (GWLB)
Layer3: IP packets via GENEVE
StrengthsTransparent insertion of security appliances
Client IPPreserved

The Classic Load Balancer is legacy. All are managed, scale automatically and span the AZs you enable.

The following diagram summarises the three types by layer.

The three Elastic Load Balancing types by layer. An Application Load Balancer works at layer 7, routes by request content and supports authentication and AWS WAF. A Network Load Balancer works at layer 4 with static IP addresses, very high throughput and the client IP preserved. A Gateway Load Balancer works at layer 3, sending packets to fleets of security appliances.
Requirements for static IP addresses or non-HTTP protocols point to an NLB; content-based routing or WAF points to an ALB.
Sort into groups

ALB, NLB or GWLB?

Exam skills 3.4.4 · 4.2.1

Choose the load balancer type for each requirement.

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

Routing and features

An ALB's listener rules examine each request and route it by host name, path, HTTP header, method, query string or source IP address, so one load balancer can serve api.example.com and www.example.com, or send /orders/* and /users/* to different services. A rule's action can forward the request to a target group, or to several weighted target groups for blue/green and canary releases, redirect it, for example from HTTP to HTTPS, or return a fixed response.

An ALB can authenticate users with Cognito or any OpenID Connect provider before requests reach the targets, so applications receive only signed-in users. Targets can be instances, IP addresses, including servers on premises, Lambda functions, and containers using dynamic ports. HTTPS listeners use ACM certificates, and several certificates on one listener serve different domains through SNI. The ALB integrates with AWS WAF and has its own security groups. The following table summarises these features.

FeatureDetail
Listener rulesRoute by host, path, HTTP header, method, query string or source IP
ActionsForward (to one or weighted target groups), redirect (such as HTTP to HTTPS), fixed response
AuthenticationCognito or OIDC authentication before requests reach targets
TargetsInstances, IPs (including on premises), Lambda functions, containers with dynamic ports
TLSACM certificates, multiple certificates per listener with SNI
SecurityAWS WAF integration; security groups on the load balancer

The following diagram shows one listener routing requests with several kinds of rule.

How an ALB's listener rules route requests. Rules examine the host name, path, headers, method, query string or source IP, and each rule's action forwards to a target group, splits traffic across weighted target groups for blue/green or canary releases, redirects, for example from HTTP to HTTPS, or returns a fixed response.
The rules are illustrative. A default rule handles requests that match no other rule.
Select all that apply

ALB capabilities

Exam skills 3.4.4 · 2.1.1

Identify what an Application Load Balancer can do.

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

Internet-facing or internal

Every load balancer has a scheme, chosen at creation. An internet-facing load balancer has public IP addresses and nodes in public subnets, and its DNS name resolves to those public addresses, so it is the public entry point for an application. Its targets can still sit in private subnets, because the load balancer reaches them over private addresses.

An internal load balancer has only private IP addresses, so it can be reached only from within the VPC, from connected VPCs or from on premises over VPN or Direct Connect. It suits traffic between the tiers of an application, such as from a web tier to an application tier, and internal services that should never be exposed to the internet. The following table summarises the two schemes.

SchemeIPsUse for
Internet-facingPublic, in public subnetsPublic entry points
InternalPrivate onlyBetween tiers, or services reached over VPN
True or false

Load balancer schemes

Exam skills 3.4.4 · 1.2.2

Check how internet-facing and internal load balancers differ.

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

Monitoring

Access logs in S3 record client IP, latency, path and response code per request. CloudWatch metrics such as HTTPCode_Target_5XX_Count, TargetResponseTime and UnHealthyHostCount drive alarms. The ALB's IP addresses change, so clients must use its DNS name.

Worked example

A load balancer for each workload

Each type of load balancer suits a different workload. The following table identifies the appropriate load balancer for several workloads and the reason in each case.

WorkloadLoad balancerWhy
Website with /api and /images handled by different servicesALBPath-based routing at layer 7
Millions of TCP connections per second for a trading platformNLBLayer 4, very high performance, low latency
Customers need static IP addresses to allow-listNLBOne static (or Elastic) IP per AZ
Route all traffic through a fleet of third-party firewallsGWLBTransparent insertion of appliances
HTTP/2 and gRPC microservicesALBSupports gRPC and HTTP/2

If a question needs both static IPs and HTTP routing, a common answer is an NLB in front of an ALB, or Global Accelerator in front of the ALB.

Check yourself

How does an application behind an ALB find the client's IP address?

Show answer

From the X-Forwarded-For header, because the ALB opens its own connection to the target.

Exam Tips

Remember for the exam

  • For path-based or host-based routing, HTTP features or Lambda targets, use an ALB.
  • To authenticate users before they reach the application without code, use ALB authentication with Cognito or OIDC.
  • For a load balancer between internal tiers, use an internal ALB.
  • To analyse the client IP address and latency of every request, use ALB access logs in S3.
  • To redirect HTTP to HTTPS, add a redirect action on the HTTP listener.