SkillSprout
Chapter 5 · Lesson 4
Intermediate
7 min read

CloudFront, Global Accelerator and Edge Operations

Overview

Amazon CloudFront is a global content delivery network. It caches content at edge locations close to users, so repeated requests are answered from the edge instead of travelling to your origin (S3 bucket, ALB, API Gateway or any HTTP server). The result is lower latency, less origin load and built-in DDoS resilience.

Think of a chain of local convenience stores stocking popular items from a central warehouse. Customers get goods quickly from the nearby shop; the warehouse is only contacted when the shelf is empty. Global Accelerator is different: it does not cache, but gives you two static anycast IPs and routes TCP/UDP traffic over the AWS backbone to the closest healthy endpoint.

Operationally you need to manage cache behaviour (TTL, invalidations), secure origins with Origin Access Control, diagnose 4xx/5xx errors and monitor the cache hit ratio.

Key Concepts

  • A distribution has origins and cache behaviors (path patterns) with cache policies (TTL, headers, cookies, query strings in the cache key) and origin request policies.
  • Cache hit ratio is the key metric; improve it by minimising cache-key variation and increasing TTL.
  • Invalidations remove objects from edge caches (/*); the first 1,000 paths a month are free; versioned file names are a cheaper alternative.
  • Origin Access Control (OAC) restricts an S3 origin so only CloudFront can read it (replaces legacy OAI); keep the bucket private.
  • Signed URLs / signed cookies restrict content to authorised viewers; geo restriction allows or blocks countries; WAF attaches to distributions.
  • Origin groups provide origin failover on specified status codes; custom error pages and error caching TTL (default 10 s) matter.
  • CloudFront Functions (lightweight viewer JS) and Lambda@Edge (heavier logic) run at the edge.
  • Global Accelerator provides static anycast IPs, health-based failover and fast regional failover for non-cacheable TCP/UDP apps; no caching.

Detailed Notes

CloudFront vs Global Accelerator

FeatureCloudFrontGlobal Accelerator
CachingYesNo
ProtocolsHTTP/HTTPS/WebSocketTCP / UDP
IPsDynamic2 static anycast IPs
Best forWeb content, APIs, streamingGaming, VoIP, static IP requirement, fast failover
FailoverOrigin groupsHealth-based endpoint failover within seconds

Cache key and TTL

SettingEffect
Min / default / max TTLBound how long objects live if origin sends Cache-Control
Cache-Control: max-age / s-maxageOrigin sets TTL within min/max
Cache key headers/cookies/query stringsMore included -> more variants -> lower hit ratio
CompressionGzip/Brotli at edge
bash
aws cloudfront create-invalidation --distribution-id E123ABC --paths "/index.html" "/css/*"
aws cloudfront get-distribution --id E123ABC --query "Distribution.Status"

Securing an S3 origin with OAC

json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "cloudfront.amazonaws.com" },
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::site-bucket/*",
    "Condition": { "StringEquals": { "AWS:SourceArn": "arn:aws:cloudfront::111122223333:distribution/E123ABC" } }
  }]
}

For SSE-KMS encrypted objects, the KMS key policy must also allow the CloudFront service principal.

Troubleshooting CloudFront errors

ErrorLikely cause
403 from S3 originOAC/bucket policy missing, object absent with no ListBucket permission, Geo restriction, WAF block, signed URL invalid
502 Bad GatewayOrigin SSL/TLS mismatch (certificate name, protocol), origin unreachable
503Origin overloaded or Lambda@Edge error
504 Gateway TimeoutOrigin took longer than the origin response timeout (default 30 s)
Stale contentTTL too long; invalidate or version file names
Low cache hit ratioForwarding cookies/headers/query strings unnecessarily; short TTL
Cert errorViewer certificate must be in us-east-1 and match the alternate domain name (CNAME)

Check the X-Cache response header (Hit from cloudfront, Miss from cloudfront, Error from cloudfront). Enable standard logs (S3) or real-time logs (Kinesis) and CloudFront additional metrics (cache hit rate, error rate by status).

Distribution fragment (CloudFormation)

yaml
Distribution:
  Type: AWS::CloudFront::Distribution
  Properties:
    DistributionConfig:
      Enabled: true
      Aliases: [www.example.com]
      ViewerCertificate:
        AcmCertificateArn: !Ref Cert
        SslSupportMethod: sni-only
      Origins:
        - Id: s3
          DomainName: !GetAtt Bucket.RegionalDomainName
          OriginAccessControlId: !GetAtt Oac.Id
          S3OriginConfig: { OriginAccessIdentity: "" }
      DefaultCacheBehavior:
        TargetOriginId: s3
        ViewerProtocolPolicy: redirect-to-https
        CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6   # Managed-CachingOptimized

Global Accelerator operations

bash
aws globalaccelerator create-accelerator --name api --ip-address-type IPV4 --enabled
aws globalaccelerator create-listener --accelerator-arn <ARN> --protocol TCP --port-ranges FromPort=443,ToPort=443

Add endpoint groups per Region with traffic dials and health checks; unhealthy endpoints are removed automatically in seconds, avoiding DNS TTL delays.### Cache behaviour, invalidation and origin protection

SettingEffect
Cache policyDefines TTLs and which headers, cookies and query strings form the cache key; forward only what the origin needs
Origin request policySends extra values to the origin without adding them to the cache key
Invalidation/* or path lists; first 1,000 paths per month free; prefer versioned file names
Origin Access Control (OAC)Keeps S3 origins private; bucket policy allows the CloudFront service principal
Origin ShieldExtra caching layer to reduce origin load
Origin failoverOrigin group with a secondary on 5xx or timeouts
Signed URLs / cookiesRestrict content to authorized users
AWS WAF / geo restrictionFilter requests at the edge
bash
aws cloudfront create-invalidation --distribution-id E123ABC --paths "/index.html" "/css/*"
aws cloudfront get-distribution-config --id E123ABC --query "DistributionConfig.CacheBehaviors"
curl -sI https://www.example.com/logo.png | grep -i -E "x-cache|age"

X-Cache: Hit from cloudfront confirms caching. Common errors: 403 from an S3 origin (OAC or bucket policy missing), 502 (TLS mismatch or origin invalid response), 504 (origin timeout). Global Accelerator instead uses anycast static IPs to route TCP/UDP to endpoints and does not cache content. Use the CloudFront CacheHitRate and OriginLatency metrics (additional metrics must be enabled).

Real World Example

Scenario – a marketing launch slows the site. A retailer's origin ALB shows 90% CPU on launch day while CloudFront reports a 35% cache hit ratio. The cache policy forwards all cookies and query strings, creating thousands of cache variants.

The team switches static paths to a managed CachingOptimized policy that ignores cookies, versions asset file names instead of invalidating, and serves the API path with a separate behavior and short TTL. Hit ratio rises to 92%, origin load falls by two-thirds, and S3 is locked down with OAC so users cannot bypass the CDN.

Architecture Diagram

CloudFront with secured origins
Architecture
AWS Cloud
Viewers
WAF
CloudFrontedge cache
S3 originOAC
ALB origindynamic API
  1. 1Viewers request content; the nearest edge location receives the request and WAF rules are evaluated.
  2. 2On a cache hit the edge responds immediately.
  3. 3On a miss CloudFront fetches from the matching origin using OAC or a custom header.
  4. 4The object is cached per the cache policy TTL and served to later viewers.

Best Practices

  • ✓Use OAC with private S3 buckets and restrict ALB origins to CloudFront (managed prefix list, secret header).
  • ✓Keep cache keys minimal and use versioned object names instead of frequent invalidations.
  • ✓Use separate behaviors for static and dynamic paths with suitable TTLs.
  • ✓Attach WAF, enforce HTTPS and enable standard logs / additional metrics.
  • ✓Use origin groups (failover) and Global Accelerator where static IPs or fast failover are required.

Common Interview Questions

Exam Tips

SOA-C03 focus

  • Reduce origin load and latency for static/global content -> CloudFront; static IPs / TCP-UDP -> Global Accelerator.
  • S3 origin private -> Origin Access Control (OAC), not public bucket.
  • Certificates for CloudFront must be in us-east-1 (ACM).
  • Remove cached object immediately -> invalidation (or versioned names).

Chapter quiz

Networking and Content Delivery Operations · 10 questions

  1. 1.Instances in a private subnet cannot download updates from the internet. The subnet route table has no default route. Which change fixes this?

  2. 2.A custom network ACL allows inbound TCP 443 but clients cannot complete connections. Security groups allow 443. What is the most likely missing configuration?

  3. 3.A company wants to analyse which source IP addresses are being rejected when connecting to port 22 in a VPC, using cost-effective long-term storage. What should they use?

  4. 4.An organization with 25 VPCs and an on-premises data centre wants simple, scalable routing with network segmentation between prod and dev. Which service should they choose?

  5. 5.A static website served from a private S3 bucket through CloudFront returns 403 errors. Which fix should be applied?

  6. 6.Instances in a subnet can receive requests on port 443 but clients never get responses. Security groups allow it. Flow Logs show ACCEPT inbound and REJECT outbound. What is wrong?

  7. 7.IPv6-only workloads in private subnets must reach the internet without allowing inbound connections. What should be used?

  8. 8.Private subnets send large volumes of data to S3 through a NAT gateway and cost is high. What is the cheapest fix?

  9. 9.Two on-premises sites and 20 VPCs must communicate with centralized routing control and segmentation between environments. Which service fits best?

  10. 10.CloudFront returns 403 for objects in a private S3 origin after the bucket policy was tightened. What should be verified?

0 of 10 answered

Finished this lesson?

0 of 46 lessons done · 0% of the course