☁︎SAA-C03

CloudFront

CloudFront — Concept

What it is

Amazon CloudFront = AWS's global CDN (Content Delivery Network). Caches content at 400+ edge POPs worldwide so users get low-latency, high-throughput delivery near them.

Why it exists

Serving static assets (and even dynamic API responses) from a single region introduces latency for distant users. Edge caching also offloads origin traffic, reducing cost and load.

How it works

  • Create a distribution pointing to an origin (S3 bucket, ALB, EC2, MediaPackage, any HTTP server).
  • DNS hands users an edge POP.
  • Edge serves cached content; on miss, fetches from origin (optionally through a regional edge cache layer).
  • Cache key controlled by cache policies (which headers/query strings/cookies form the key).
  • Origin request policies control what is forwarded to origin.
  • Response headers policies add CORS / security headers.

Origin types

  • S3 bucket — most common for static sites and assets.
  • S3 website endpoint — supports index/error docs (redirects, etc.).
  • HTTP origin — ALB, EC2, on-prem, or any HTTPS URL.
  • MediaStore / MediaPackage — video.

Security features

FeatureWhat it does
HTTPS / TLSFree ACM certs (must be in us-east-1 for CloudFront).
OAC (Origin Access Control)Locks an S3 origin so only the CloudFront distribution can read it (replaces older OAI).
Signed URLsOne URL = one user; expire after time.
Signed CookiesOne cookie = many URLs; for whole sections of a site.
Geo restrictionAllow/block by country (built-in).
AWS WAFAttach a WebACL to filter at edge.
AWS ShieldDDoS mitigation (Std free, Advanced extra).
Field-level encryptionEncrypt specific form fields end-to-end (PII / PCI).

Cache vs Origin Request policies

  • Cache policy — defines what makes responses different in the cache (cache key) and TTLs.
  • Origin request policy — defines what to forward to the origin without affecting the cache key.

Lambda@Edge & CloudFront Functions

Lambda@EdgeCloudFront Functions
RuntimeNode.js / PythonLightweight JS
WhereEdge regions (4 trigger points)Edge POPs
Latencymssub-ms
UseComplex logic, requests to other AWS servicesHeader rewriting, simple auth, URL redirect
Costper ms + invocationsinvocations only, ~⅙ price

TTL behavior

  • Default TTL, Min TTL, Max TTL set on cache behavior.
  • Origin can override via Cache-Control headers (s-maxage, max-age).
  • Invalidations flush objects manually (priced per path; first 1,000 a month free).

Pricing model (high level)

  • Data transfer out to internet from edge.
  • Data transfer to origin.
  • HTTPS requests.
  • Optional Lambda@Edge / CloudFront Functions invocations.
  • Price tiered by edge region (NA/EU cheapest; SA, IN, ZA most expensive). Use Price Class All / 200 / 100 to limit POPs and cost.

When to use vs alternatives

Use ...Instead of ...When ...
CloudFrontS3 directNeed low latency globally, HTTPS, signed access
CloudFrontALB onlyCache static or dynamic content, reduce origin load, add WAF at edge
Global AcceleratorCloudFrontNon-HTTP (TCP/UDP), gaming, real-time, static anycast IPs
S3 Transfer AccelerationCloudFrontUploads to S3 from far away (uses CF POPs in reverse)

Common exam scenarios

  1. "Static website with global users, low cost" → S3 + CloudFront (OAC) + ACM in us-east-1.
  2. "Premium content, paid users only, per-user URL"Signed URLs.
  3. "Premium content, paid users only, many files"Signed Cookies.
  4. "Block users from country X"Geo restriction.
  5. "Lock down S3 origin from public"OAC on origin + bucket policy referencing distribution.
  6. "Rewrite a header at edge cheaply"CloudFront Function.
  7. "Reduce upload time for large file from Asia to us-east-1"S3 Transfer Acceleration.

Exam tip

  • ACM cert for CloudFront must be in us-east-1 (only region).
  • OAC has replaced OAI — prefer OAC in new designs.
  • CloudFront is HTTP/HTTPS only. Need TCP/UDP at edge → Global Accelerator.

References