AWS CloudFront CDN

Beginner
12 min read
Updated: Nov 2026
5 examples
CDN / ALB origin

Definition and Usage

Amazon CloudFront is AWS’s content delivery network (CDN). It terminates viewer requests at edge locations worldwide, can cache responses, and fetches misses from an origin—in this guide, an Application Load Balancer.

What problem does CloudFront solve?

Users far from your ALB Region see higher latency if every request hits the origin. CloudFront shortens that path for cacheable content, absorbs spikes at the edge, and can enforce HTTPS closer to viewers.

When should you use CloudFront?

Put CloudFront in front of an ALB when you want global performance, edge TLS, optional AWS WAF, and a single public hostname. For static files alone, many teams use S3 (or S3 + CloudFront) instead of an ALB origin.

How traffic flows

Viewer → CloudFront edge → (cache hit) response, or (cache miss) origin protocol to your ALB → target group → healthy instances. DNS usually points at CloudFront via Route 53, not directly at the ALB.

Custom domains and ACM

Alternate domain names (CNAMEs) need a certificate from ACM in us-east-1, even if the ALB certificate lives in another Region. Then alias your domain to the distribution in Route 53.

Edge cache + origin.

Static and cacheable responses stay near viewers. Dynamic or uncacheable requests still reach the ALB with policies you control.

ACM for CloudFront is us-east-1 only.

Viewer certificates on the distribution must be requested or imported in N. Virginia. ALB HTTPS certs stay in the ALB Region.

Prefer HTTPS to the origin.

Use an origin protocol policy of HTTPS only (or Match viewer with care) and TLS 1.2+ so traffic is encrypted CloudFront→ALB as well as viewer→CloudFront.

Core Concepts

Terms you will see while creating a distribution:

ConceptMeaning
DistributionThe CloudFront config that serves your site or API at the edge
OriginWhere CloudFront fetches content (here: ALB DNS name)
Edge locationPoP that answers viewers; may cache responses
Cache behaviorPath pattern rules for protocol, methods, and caching
Cache policyWhat makes the cache key (TTL, query strings, headers, cookies)
Origin request policyWhat CloudFront forwards to the origin on a miss
Alternate domain (CNAME)Your hostname (e.g. www.example.com) instead of *.cloudfront.net
InvalidationPurge cached paths so the next hit refetches from the origin

Prerequisites

Have these ready before you create the distribution:

  • An AWS account with access to CloudFront, Route 53, and your ALB.
  • An Application Load Balancer already serving your app (HTTPS recommended via ACM).
  • A Route 53 hosted zone (or other DNS) you can point at CloudFront. For a custom domain on the distribution, an ACM cert in us-east-1.

Examples

Create a distribution with an ALB origin, tune caching, point DNS at the edge, then invalidate when needed.

Example 1 — Set the ALB as Origin

Start a distribution and point CloudFront at your load balancer.

  1. Open CloudFront in the AWS console and choose Create distribution.
  2. Under Origin, set Origin domain to your Application Load Balancer.
  3. Set Origin protocol policy (prefer HTTPS only) and Minimum origin SSL protocol to at least TLS 1.2.
CloudFront console Create distribution
AWS Management Console
CloudFront origin domain and protocol policy for an ALB
CloudFront
CloudFront minimum origin TLS version
CloudFront

How It Works

  1. The origin is where misses go—here the public ALB DNS name.
  2. Origin protocol policy chooses HTTP or HTTPS for CloudFront→ALB.
  3. TLS 1.2+ avoids weak protocols between the edge and your origin.
  4. ALB security groups must still allow the traffic CloudFront sends to the listener ports.

Example 2 — Default Cache Behavior and Policies

Control how viewers connect and what becomes part of the cache key.

  1. Under Default cache behavior, set Viewer protocol policy (often redirect HTTP to HTTPS) and Allowed HTTP methods for your app.
  2. Under Cache key and origin requests, use recommended settings or pick a cache policy and origin request policy.
  3. Optional: enable AWS WAF if you want a web ACL at the edge.
CloudFront default cache behavior settings
CloudFront
CloudFront cache key and origin request policies
CloudFront
CloudFront optional WAF security options
CloudFront

How It Works

  1. Viewer protocol policy forces or allows HTTPS at the edge (pair with HTTP→HTTPS habits).
  2. Allowed methods must include POST/PUT if your API needs them; GET/HEAD alone is fine for static sites.
  3. Cache policy decides what makes two requests share a cached object.
  4. Origin request policy decides which headers, cookies, and query strings reach the ALB on a miss.

Example 3 — Settings, Certificate, and Create

Add your domain, attach a us-east-1 certificate, then deploy the distribution.

  1. Under Settings, choose a Price class and add an Alternate domain name (CNAME) if you use a custom hostname.
  2. Attach a custom SSL certificate from ACM in us-east-1 when using that custom domain.
  3. Review HTTP versions and defaults, then choose Create distribution and wait until status is Deployed.
CloudFront general settings price class and alternate domain
CloudFront
CloudFront supported HTTP versions
CloudFront
CloudFront distribution created successfully
CloudFront

How It Works

  1. Price class trades cost vs how many edge locations you use.
  2. Alternate domain names let viewers use www.example.com instead of d123.cloudfront.net.
  3. ACM in us-east-1 proves you own those names for CloudFront TLS.
  4. Deployed means edges have the config; DNS may still point at the ALB until you update it.

Example 4 — Point Route 53 at CloudFront

Send public traffic to the distribution instead of the ALB DNS name.

  1. Open Route 53 and select your hosted zone.
  2. Edit the record for your site: alias A (and AAAA if needed) to the CloudFront distribution.
  3. Save and wait for DNS TTL to expire for clients.
Route 53 alias record pointing to CloudFront distribution
Route 53

How It Works

  1. Viewers resolve your domain to CloudFront, not the raw ALB hostname.
  2. Alias records in Route 53 target the distribution without hard-coding IPs.
  3. The ALB stays the origin—CloudFront still fetches from it on cache misses.
  4. Optional hardening: restrict direct ALB access so only CloudFront can reach it (security groups / managed prefixes).

Example 5 — Invalidate Cached Paths

Force edges to drop stale objects after a deploy.

  1. Open your distribution → Invalidations → Create invalidation.
  2. Enter paths such as /index.html or /* (use broad paths sparingly).
  3. Submit and wait until the invalidation completes.
CloudFront create cache invalidation
CloudFront

How It Works

  1. Edges keep objects until TTL expires or you invalidate.
  2. A path invalidation removes matching cached entries so the next request refetches the origin.
  3. /* clears everything for that distribution—handy, but watch quotas and cost.
  4. Better habit: version static filenames (app.abc123.js) so you rarely need invalidations.

Edge Cases & Pitfalls

Most CloudFront surprises come from the wrong ACM Region, over-caching, or DNS still aimed at the ALB.

acm

Certificate not in us-east-1

CloudFront will not list ALB-Region certificates for viewer HTTPS. Request a separate ACM cert in N. Virginia for alternate domain names.

dns

DNS still points at the ALB

Creating a distribution does not move traffic. Update Route 53 (or your DNS) to alias the hostname to CloudFront.

cache

Caching personalized or API responses

If cookies or auth headers matter, use policies that exclude them from the cache key—or disable caching for those paths.

host

Host-header rules on the ALB

If the ALB routes on Host, forward the right Host header via the origin request policy, or add rules for both your domain and the CloudFront domain.

tls

Origin certificate name mismatch

HTTPS to the ALB needs a cert that matches the origin domain / Host you send. Prefer a custom domain on the ALB over relying on the default *.amazonaws.com name.

cost

Broad invalidations and WAF costs

/* invalidations and always-on WAF add spend. Use versioned assets and attach WAF only when you need the rules.

Key Takeaways

  • Role: CloudFront is the global edge in front of your origin (here, an ALB).
  • TLS: viewer certs for custom domains come from ACM in us-east-1; prefer HTTPS to the origin.
  • Policies: cache and origin request policies control hit ratio and what the ALB sees.
  • Cutover: alias DNS to CloudFront; invalidate or version assets after deploys.

One line: CloudFront at the edge, ALB as origin, DNS alias to the distribution, ACM in us-east-1 for custom domains.

Frequently Asked Questions

AWS CloudFront is a content delivery network (CDN) that caches and delivers web content, APIs, and media through a global network of edge locations for lower latency and higher transfer speeds.
Yes. Use the ALB DNS name as a custom origin, set an origin protocol policy (HTTPS only is recommended), and ensure security groups and health checks allow CloudFront to reach your targets.
Custom SSL certificates for CloudFront alternate domain names must come from ACM in us-east-1 (N. Virginia), even when your ALB or other origins live in another Region.
An invalidation tells CloudFront to drop cached objects matching specified paths so the next requests fetch fresh content from the origin. Prefer versioned asset filenames when you can to reduce invalidations.
After CloudFront is deployed, point viewer DNS (usually a Route 53 alias A/AAAA) at the CloudFront distribution. Keep the ALB as the origin only—not the public entry point—if you want traffic to use the edge.
No. WAF is optional. Enabling it can block common web exploits at the edge but adds configuration and cost. You can attach a web ACL later.

Next: AWS WAF

Attach a web ACL to filter exploits and noisy traffic at the edge.

AWS WAF tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful