Skip to content
Visual explainer 3h to learn 5 steps

Choose load balancers, DNS, CDN and hybrid links on AWS

Trace traffic scenarios through ALB, NLB, Route 53, CloudFront, WAF, Transit Gateway, VPN and Direct Connect and pick one per case.

By Invicly Tech, , in AWS Cloud Engineering. About 13 minutes to read.

Topic 9 of 38

In short

Traffic reaches an AWS application through a chain of services: Route 53 answers the DNS lookup, CloudFront caches content near users, AWS WAF filters bad requests, and a load balancer spreads requests across healthy targets. Behind the scenes, Transit Gateway joins many VPCs, and Site-to-Site VPN or Direct Connect link them to an office or data centre. Each service solves one job, and picking the right one starts with the traffic flow you need.

Think of it like this: Route 53 is the phone book, CloudFront is a local shop that keeps popular items in stock, WAF is the door check, the load balancer is the receptionist sending visitors to a free desk, and Transit Gateway is the company's internal switchboard.

Explained simply

So far our service lives inside a VPC. Now users and other networks need to reach it. A handful of AWS services sit at the edge of that path, each with one clear job.

Route 53 is DNS. It turns files.example.com into an address, and it can give different answers to different users, such as the nearest Region or a backup site when the main one is down. CloudFront is a content delivery network. It keeps copies of files in edge locations near users, so pages load faster and your servers do less work.

AWS WAF is a web application firewall. It inspects HTTP requests and blocks ones that match rules, such as too many requests from one IP or known attack patterns. A load balancer then spreads the good requests across healthy servers or containers. The Application Load Balancer understands HTTP paths and hosts. The Network Load Balancer handles raw TCP and UDP very fast.

Some traffic comes from your own office or data centre instead of the internet. Site-to-Site VPN builds encrypted tunnels over the internet and can be ready the same day. Direct Connect is a private physical link that takes longer to set up but gives steady speed. Transit Gateway joins many VPCs and these links in one hub.

Press Play on a diagram to walk through it one step at a time.

FlowA browser request to the file-processing app
  1. 1
    Route 53

    files.example.com resolves to CloudFront

  2. 2
    CloudFront edge

    Serves cached static files near the user

  3. 3
    AWS WAF

    Blocks bad IPs, rate floods and common attacks

  4. 4
    Application Load Balancer

    Routes /api/* to healthy targets

  5. 5
    Targets in private subnets

    Containers or instances handle the request

CompareSite-to-Site VPN versus Direct Connect
Site-to-Site VPN
  • Encrypted IPsec tunnels over the internet
  • Set up in hours
  • Two tunnels per connection for redundancy
  • Speed and latency vary with the internet
Direct Connect
  • Private dedicated link via a partner location
  • Takes weeks to order and install
  • Steady latency and high bandwidth
  • Not encrypted by default; add VPN or MACsec
SequenceRoute 53 failover when the primary Region is down
User resolver
Route 53
Health checker
Backup ALB
  1. 1Primary /health failed 3 checks in a row
    Health checker to Route 53: Primary /health failed 3 checks in a row
  2. 2Query api.example.com after TTL expires
    User resolver to Route 53: Query api.example.com after TTL expires
  3. 3Answer with the secondary (backup) record
    Route 53 to User resolver: Answer with the secondary (backup) record
  4. 4HTTPS request to the backup Region
    User resolver to Backup ALB: HTTPS request to the backup Region
  5. 5Response served from the backup stack
    Backup ALB to User resolver: Response served from the backup stack

In depth

ALB or NLB: decide by protocol and features

An Application Load Balancer terminates HTTP and HTTPS. It can route by host name, path, headers, query strings or source IP, send different paths to different target groups, return fixed responses and redirects, and authenticate users with an identity provider. It works with instances, IP addresses, Lambda functions and ECS tasks. It is the default for web apps and APIs.

A Network Load Balancer works at layer 4. It forwards TCP, UDP and TLS connections with very low added latency, keeps a static IP per zone (or an Elastic IP you assign), and preserves the client's source IP. Choose it for non-HTTP protocols, for clients that need a fixed IP allow-list, or to offer a service to other VPCs through PrivateLink. Both run health checks and only send traffic to healthy targets.

CompareALB and NLB in practice
Application Load Balancer
  • HTTP, HTTPS, gRPC
  • Path, host and header rules
  • Targets: instances, IPs, Lambda
  • Pairs with WAF directly
Network Load Balancer
  • TCP, UDP, TLS
  • Static IP per zone
  • Very high connection rates
  • Fronts PrivateLink endpoint services

Route 53 routing policies

Route 53 is a global DNS service. Alias records point a name such as files.example.com straight at CloudFront, an ALB or an S3 website, and alias queries to AWS resources are free. Routing policies decide which answer a resolver gets. Simple returns one answer. Weighted splits traffic by weight, useful for gradual releases. Latency picks the Region with the lowest latency for that user. Failover returns a primary record while its health check passes and a secondary when it fails. Geolocation answers by the user's country or continent, which helps with data residency. Geoproximity, multivalue answer and IP-based routing cover more special cases.

DNS answers are cached for the record's TTL, so failover is never instant. Keep TTLs short, such as 60 seconds, on records you plan to switch.

  • Weighted: 90 to stable, 10 to new
  • Failover: primary plus health check, secondary as backup
  • Latency: nearest Region by measured latency
  • Short TTLs make changes take effect faster

CloudFront and WAF at the edge

CloudFront is a CDN with many edge locations worldwide. A distribution has one or more origins, such as an S3 bucket for static files and an ALB for the API, and cache behaviours that send each path pattern to an origin with its own caching rules. Static assets can be cached for days; API paths are usually not cached at all but still benefit from TLS ending close to the user.

For S3 origins, use origin access control so the bucket stays private and only CloudFront can read it. For an ALB origin, add a custom secret header at CloudFront and have the ALB reject requests without it, or restrict the ALB security group to the CloudFront managed prefix list. Attach a WAF web ACL to the distribution (or to the ALB, API Gateway and some other resources) with managed rule groups and a rate-based rule. Start rules in count mode, watch the logs, then switch to block.

Joining networks: Transit Gateway, VPN and Direct Connect

VPC peering joins two VPCs directly, but it is not transitive: if A peers with B and B with C, A still cannot reach C. With many VPCs, the mesh of peerings grows fast. Transit Gateway is a regional hub instead. Each VPC, VPN and Direct Connect gateway attaches once, and Transit Gateway route tables decide who can talk to whom, for example letting every app VPC reach shared services but not each other. You pay per attachment per hour and per GB processed.

Site-to-Site VPN gives each connection two IPsec tunnels ending in different AWS endpoints, so one can fail without an outage. Direct Connect is a private circuit through a Direct Connect location, ordered as a dedicated port or through a partner. Many companies run Direct Connect as the main path and VPN as the backup.

MapA hub-and-spoke network with Transit Gateway
Transit Gateway (one Region)
  • App VPCs
    • Dev VPC
    • Prod VPC
  • Shared services VPC
    • Central DNS
    • Inspection firewall
  • Hybrid links
    • Direct Connect gateway (primary)
    • Site-to-Site VPN (backup)
  • TGW route tables
    • Apps reach shared services
    • Apps cannot reach each other

Learn it in 5 short steps

About 35m each. Track them with a timer in your plan.

  1. 1
    Compare ALB and NLB~35m
  2. 2
    Route with Route 53 policies~35m
  3. 3
    Cache and protect with CloudFront and WAF~35m
  4. 4
    Join VPCs with Transit Gateway~35m
  5. 5
    Compare Site-to-Site VPN and Direct Connect~35m

Key points

  • ALB works at layer 7 and routes by host, path or header; NLB works at layer 4 for TCP, UDP and TLS with static IPs.
  • Route 53 routing policies (weighted, latency, failover, geolocation) decide which answer each user gets.
  • CloudFront caches at the edge and can sit in front of S3, an ALB or any HTTP origin.
  • Transit Gateway is a regional hub that replaces a tangle of VPC peering links.
  • Use VPN to start fast or as a backup; use Direct Connect for steady, high-volume hybrid traffic.

Key terms

Tap a card to flip it. 0/6 known

Examples

Choosing the edge stack for the file-processing app

Requirements: a web page for uploads, a JSON API, visitors in Europe and Asia, and protection from scripted floods. Step 1: put the static page in a private S3 bucket behind CloudFront with origin access control. Step 2: add a second origin, the ALB, for /api/* with caching off. Step 3: attach a WAF web ACL with the AWS managed common rule set and a rate-based rule per IP. Step 4: create a Route 53 alias record for files.example.com pointing to the distribution. Step 5: lock the ALB security group to the CloudFront managed prefix list so nobody can bypass WAF. Design-only alternative: draw the flow without deploying, since CloudFront and WAF carry small charges.

Connecting a branch office: VPN now, Direct Connect later

A finance office must reach the private API in the prod VPC this week, and next year it will move 5 TB a month. Step 1: create a customer gateway with the office router's public IP and a Site-to-Site VPN attached to a Transit Gateway. Step 2: configure both tunnels on the office router, using BGP so routes update automatically. Step 3: add a TGW route table entry so the office reaches only the prod VPC. Evidence: both tunnels show UP and a curl to the private ALB works from the office. Later, add Direct Connect as the primary path and keep the VPN as backup. Use 192.168.0.0/16 or similar non-overlapping office ranges in your plan.

bash
aws ec2 create-customer-gateway --type ipsec.1 \
  --public-ip 203.0.113.10 --bgp-asn 65010
aws ec2 create-vpn-connection --type ipsec.1 \
  --customer-gateway-id cgw-0officeexample \
  --transit-gateway-id tgw-0hubexample
aws ec2 describe-vpn-connections \
  --query "VpnConnections[].VgwTelemetry[].Status"   # expect UP, UP

Quick reference

  • ALB = layer 7 HTTP routing; NLB = layer 4 TCP/UDP/TLS with static IPs
  • Route 53 alias records can point at CloudFront, ALB and S3 websites
  • Weighted, latency, failover and geolocation are the Route 53 policies you use most
  • CloudFront + origin access control keeps the S3 bucket private
  • Start WAF rules in count mode, then switch to block
  • VPC peering is not transitive; Transit Gateway is the hub for many VPCs
  • Each Site-to-Site VPN has two tunnels; configure both
  • Direct Connect is private but not encrypted by default

Common mistakes

  • Using an NLB when you need path-based routing or HTTP header rules, which only an ALB provides.
  • Leaving the ALB open to the internet after putting CloudFront in front, so attackers can skip WAF.
  • Ordering Direct Connect without a VPN backup, so one fibre cut takes the hybrid link down.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1A partner must allow-list fixed IP addresses for your TCP service. Which load balancer fits?

Question 2

2You want 5 percent of users on a new stack for a week. Which Route 53 policy?

Question 3

3VPC A peers with B, and B peers with C. Can A reach C through B?

Question 4

4CloudFront with WAF fronts your ALB, but attacks still reach the ALB directly. What fixes this?

Question 5

5Which hybrid option can be running the same day over the existing internet link?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    For each case pick ALB or NLB: a REST API with /v1 and /v2 paths, a game server on UDP, an internal gRPC service, a service shared with other VPCs over PrivateLink.

  2. Exercise 2medium

    Design Route 53 records so api.example.com uses eu-west-1 normally and us-east-1 only when the primary fails.

  3. Exercise 3hard

    Ten app VPCs, one shared services VPC and an office must connect. Apps may reach shared services and the office, but not each other. Describe the Transit Gateway route tables.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Do I need CloudFront if I already have a load balancer?
Not always. CloudFront helps when users are far away, when you serve many static files, or when you want WAF and DDoS protection at the edge. A small internal API may not need it.
Is Route 53 regional or global?
Route 53 is a global service. Its health checks and DNS answers are not tied to one Region, which is why it works well for cross-Region failover.
Is Direct Connect encrypted?
Not by default. It is private, but if you need encryption run a VPN over it or use MACsec on supported dedicated connections.
How do I practise this without paying?
Draw the traffic flows as design exercises, and deploy only the cheap parts briefly, such as a Route 53 health check or a small ALB, then delete them. Hosted zones and load balancers bill even when idle.

Go deeper

ShareXLinkedInWhatsApp