Networking and Content Delivery · Topic 5 of 6

CloudFront and Global Accelerator

Speed up and protect content with CloudFront origins, caching, invalidation, origin access control and signed URLs, and compare it with Global Accelerator.

  • 5 min
  • Includes a diagram
In a nutshell
  • CloudFront caches content at edge locations, with S3, ALB, EC2 or any HTTP origin.
  • TTL and the cache key control hit ratio, so forward only needed headers and cookies.
  • Invalidate paths to remove content early, or use versioned file names.

What it is

Amazon CloudFront is a content delivery network (CDN). It keeps copies of your content at edge locations close to users, so repeated requests are answered nearby instead of travelling to your origin each time.

AWS Global Accelerator is a different tool. It gives your application static IP addresses and sends traffic over the AWS global network to the best healthy Regional endpoint.

Userbrowsernearest edgeCloudFrontedge locationcache missOriginS3 or ALB

How it works

Distributions and origins

You create a distribution that has one or more origins. An origin can be an S3 bucket, an Application Load Balancer, an EC2 instance, an API Gateway endpoint or any HTTP server. Cache behaviors map URL path patterns to origins and set rules such as allowed methods and caching settings.

An origin group provides failover: if the primary origin returns configured error codes, CloudFront tries the secondary.

Caching

When a user requests an object, the edge location checks its cache. A hit is returned immediately, and a miss is fetched from the origin and stored. The cache policy decides what is part of the cache key (headers, cookies, query strings) and how long objects live (TTL).

  • A longer TTL improves hit ratio and reduces origin load.
  • Forwarding extra headers or cookies in the cache key lowers the hit ratio, so forward only what the origin needs.
  • Compression and HTTP/2 or HTTP/3 improve speed.

To remove content before the TTL ends, create an invalidation for a path. A better habit for static files is to use versioned file names, such as app.v2.js, which avoids invalidations.

# AWS CLI: invalidate cached files
aws cloudfront create-invalidation \
  --distribution-id E1ABCDEXAMPLE \
  --paths "/index.html" "/css/*"

Protecting the origin and content

A viewer request passes AWS WAF on the CloudFront distribution to the edge location; a cache miss goes to a private S3 bucket that only CloudFront can read through origin access control, or to an ALB origin whose security group allows the CloudFront prefix list.

  • Origin access control (OAC) lets only CloudFront read a private S3 bucket. The bucket policy allows the CloudFront service for that distribution, and the bucket stays non public. OAC replaces the older origin access identity.
  • Signed URLs and signed cookies limit access to paying or logged in users.
  • Geographic restrictions allow or block countries.
  • HTTPS can be required between the viewer and CloudFront (viewer protocol policy) and between CloudFront and the origin. A custom domain needs a certificate from AWS Certificate Manager in US East (N. Virginia).
  • AWS WAF can be attached to a distribution to filter requests at the edge.
  • For ALB or custom origins, restrict the origin security group to the CloudFront managed prefix list, or require a secret custom header.

Running code at the edge

CloudFront Functions run lightweight JavaScript for simple tasks such as URL rewrites or header changes at very low latency. Lambda@Edge runs fuller functions for more complex logic. Both run at CloudFront events without servers to manage.

Troubleshooting CloudFront

SymptomLikely cause
Users see old contentCached object not expired. Invalidate or lower the TTL
403 from an S3 originBucket policy or OAC misconfigured, or object missing
502 Bad GatewayCloudFront cannot connect to the origin, often a TLS or protocol mismatch
504 Gateway TimeoutOrigin too slow or unreachable, check security groups and origin response time
Low cache hit ratioCache key includes too many headers, cookies or query strings

Global Accelerator

Global Accelerator provides two static anycast IP addresses. It routes TCP and UDP traffic to endpoints such as Application Load Balancers, Network Load Balancers, EC2 instances and Elastic IP addresses, in one or more Regions. It performs health checks and shifts traffic away from unhealthy endpoints quickly, without waiting for DNS caches to expire.

QuestionCloudFrontGlobal Accelerator
Caches content at the edgeYesNo
Static entry IP addressesNoYes
Best forWeb content, APIs, streamingNon HTTP protocols, fast Regional failover, fixed IPs
ProtocolsHTTP and HTTPS (plus WebSocket)TCP and UDP
Userfixed anycast IPentersGlobal AcceleratorAWS edgebest healthy pathALB or NLBRegion

S3 Transfer Acceleration is also edge based, but only for faster uploads and downloads to an S3 bucket from far away.

Exam tip

Cacheable content or global web delivery points to CloudFront. Static IP addresses, TCP or UDP applications, or instant Regional failover point to Global Accelerator.

What to remember for the exam

  • CloudFront caches content at edge locations, with S3, ALB, EC2 or any HTTP origin.
  • TTL and the cache key control hit ratio, so forward only needed headers and cookies.
  • Invalidate paths to remove content early, or use versioned file names.
  • OAC keeps an S3 origin private and reachable only through CloudFront.
  • Signed URLs and cookies restrict access, and geo restriction limits countries.
  • Certificates for CloudFront come from ACM in US East (N. Virginia).
  • CloudFront Functions suit light edge logic, and Lambda@Edge suits heavier logic.
  • Global Accelerator gives static anycast IPs and fast failover for TCP and UDP, and does not cache.
  • Origin groups give CloudFront origin failover.

Common mistakes

Making the S3 bucket public for CloudFront. Use OAC and keep the bucket private.

Invalidating on every deploy. Use versioned file names to avoid the work and the cost.

Forwarding all cookies and headers. The cache fragments and almost every request misses.

Requesting the certificate in the wrong Region. CloudFront needs it in US East (N. Virginia).

Choosing CloudFront for a non HTTP game server. CloudFront serves HTTP content. Global Accelerator handles TCP and UDP.

Watch out

Caching personalised or private responses can show one user's data to another. Mark such responses as not cacheable, or include the user identity in the cache key.

Check yourself

Try these three.

  • How do you let only CloudFront read a private S3 bucket?

    Use origin access control and a bucket policy that allows the CloudFront distribution.

  • Users still see an old file after deployment. What are two fixes?

    Create an invalidation for the path, or use versioned file names with a short or no cache time on the entry page.

  • Which service gives static IPs and fast failover between Regions?

    AWS Global Accelerator.

Topic 5 of 6 in Networking and Content Delivery

Test yourself on Networking and Content Delivery

The full AWS SOA-C03 question bank has 850 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.