CloudFront & Edge
AWS SAA SAA-C03 · Design High-Performing Architectures
CloudFront: content delivery at the edge
Amazon CloudFront is a content delivery network (CDN). It caches copies of your content at edge locations — data centers in cities around the world — so users download from a location near them instead of from your origin server. The result is lower latency and less load on the origin. A CloudFront distribution defines how content is served: its origin is where CloudFront fetches content it does not already have cached (an S3 bucket, an ALB, an EC2 instance, or any HTTP server), and its cache behaviors define which requests are cached, for how long, and how they are handled.
When a user requests an object, CloudFront checks the nearest edge location. On a cache hit, it serves the object immediately. On a cache miss, it fetches the object from the origin, serves it, and stores a copy for the next request. The time to live (TTL) controls how long an object stays cached; when content changes, you can invalidate the cached copy to force CloudFront to fetch the new version, although invalidations take minutes and are best used sparingly — versioned filenames are the cleaner way to publish updates. CloudFront serves content over HTTPS, integrates with AWS Certificate Manager for custom domain certificates, and supports HTTP/2 and HTTP/3.
Securing and controlling access to content
CloudFront is also a security layer. When the origin is an S3 bucket, Origin Access Control (OAC) restricts bucket access so that only CloudFront can read the objects — users cannot bypass the CDN and go straight to S3. OAC is the current recommended mechanism (it replaces the older Origin Access Identity, OAI). For content that should only be available to certain users, signed URLs and signed cookies grant time-limited access: a user without a valid signed URL gets an error. Geo restriction (also called geo-blocking) can allow or deny access by country. And AWS WAF integrates with CloudFront to filter malicious requests — SQL injection attempts, cross-site scripting, rate-based rules — before they reach the origin.
Running code at the edge: Lambda@Edge and CloudFront Functions
CloudFront can run code at edge locations, close to users. CloudFront Functions is for lightweight, high-volume tasks that run on every request: URL rewrites, header manipulation, simple redirects, and basic authorization checks. It runs on the viewer-facing triggers only and has tight resource limits. Lambda@Edge is more powerful: it runs full Lambda functions at the edge on both viewer and origin triggers, supporting heavier logic such as dynamic content generation, authentication flows, and A/B testing — at higher cost and latency than CloudFront Functions. The exam's rule: use CloudFront Functions for simple request/response tweaks, Lambda@Edge when you need real compute or access to the network and origin triggers.
Global Accelerator and the edge family
AWS Global Accelerator is often confused with CloudFront, but it solves a different problem. CloudFront caches content at the edge; Global Accelerator improves the network path for traffic that cannot be cached — dynamic API calls, gaming, real-time applications. It gives your application two static anycast IP addresses, and user traffic enters the AWS global network at the nearest edge location, then travels over AWS's private backbone to your application in the closest Region, avoiding the unpredictable public internet. Global Accelerator also provides automatic failover between Regions: if the endpoint in one Region fails health checks, traffic shifts to a healthy endpoint elsewhere. The decision rule: cacheable static content goes through CloudFront; non-cacheable dynamic traffic that needs low latency and global failover goes through Global Accelerator.
Two related services round out the edge picture. Amazon Route 53 (covered in its own guide) provides DNS routing that can direct users to the nearest healthy endpoint. AWS Outposts extends AWS infrastructure into your own data center for workloads that must run on-premises for latency or data-residency reasons — rarely the answer in SAA questions, but worth knowing as the hybrid option.
Caching behavior in depth
CloudFront's performance depends on how it decides what to cache and for how long. Each cache behavior matches a URL path pattern (such as /images/*) to settings: which origin to use, how long to cache, and which request elements form the cache key. By default the cache key is the URL, but you can include headers, cookies, or query strings when the response depends on them — for example, including the Accept-Language header when the origin serves different content per language. Including too much in the cache key fragments the cache and reduces the hit rate, so the exam favors minimal cache keys. Cache policies and origin request policies separate these concerns: the cache policy controls what goes into the cache key and the TTL values, while the origin request policy controls what is forwarded to the origin on a cache miss.
TTL values deserve care. The default TTL applies when the origin does not specify a caching duration; the minimum and maximum TTL bound what the origin can request. Setting TTLs too short sends too much traffic to the origin; setting them too long serves stale content. The cleanest way to publish updates is versioned filenames (app-v2.js instead of app.js), which sidestep caching entirely because the new file has a new URL. Price classes let you limit which edge locations serve your content, trading global reach for lower cost — useful when your users are concentrated in one part of the world. CloudFront also supports real-time log delivery to Kinesis Data Streams for immediate visibility into requests, and standard access logs to S3 for analysis.
Multiple origins and origin failover
A distribution can have more than one origin, and cache behaviors route different paths to different origins — for example, /api/* to an Application Load Balancer and everything else to an S3 bucket. Origin groups add failover: you designate a primary origin and a secondary origin, and CloudFront automatically retries the secondary when the primary returns an error status (such as 500, 502, 503, or 504). This is the standard pattern for serving a static fallback site from S3 when the application origin is unhealthy. CloudFront also supports custom origins — any HTTP server, including one outside AWS — so it can accelerate content that does not live on AWS at all. When the origin is an ALB or EC2 instance, CloudFront can be configured to forward the original viewer information (IP address, protocol) in headers so the application still sees the real client. Combined with OAC for S3 origins, WAF for request filtering, and signed URLs for restricted content, these features make CloudFront the front door for most public-facing AWS architectures.
CloudFront pricing notes
CloudFront charges for data transfer out to viewers and for the number of requests served, with prices varying by edge location region. Data transfer from the origin to CloudFront is free, and the first 1,000 invalidation paths each month are free. Because cached responses are served from the edge rather than the origin, a high cache hit ratio usually lowers the total cost of serving content compared with serving it directly from S3 or EC2.
Exam traps to watch for
- Using CloudFront for dynamic, non-cacheable traffic. CloudFront caches content; Global Accelerator improves the network path for traffic that cannot be cached.
- Using Origin Access Identity (OAI) when Origin Access Control (OAC) is the current mechanism for restricting S3 origins to CloudFront.
- Forgetting that cache invalidation is the slow way to update content — versioned filenames avoid the problem entirely.
- Choosing Lambda@Edge for simple header rewrites or redirects. CloudFront Functions is cheaper and faster for lightweight viewer-trigger logic.
Practice questions
Test yourself on this guide. Answers are checked instantly, with a full explanation for each question.
Q1.A company serves product images from an S3 bucket to users worldwide. Users in distant Regions report slow load times, and the S3 request costs are high. Which solution BEST improves performance and reduces origin load?
Explanation: CloudFront caches the images at edge locations near users, so repeat requests are served from the cache instead of hitting S3 — cutting both latency and origin request costs. Option D speeds up uploads to S3 but does not cache content for downloads. Option A protects against overwrites and does nothing for performance. Option B moves static content onto a single server, which is slower for distant users and adds a single point of failure.
Exam objective: SAA-C03 Task Statement 3.4: Determine high-performing and/or scalable network architectures
Q2.A company serves private video content through CloudFront from an S3 origin. Users must not be able to access the videos by going directly to the S3 bucket URL. Which solution enforces this?
Explanation: Origin Access Control restricts the bucket policy so that only the CloudFront distribution can read the objects; direct S3 URLs return an access-denied error. Option D does the opposite of what is required. Option C keeps the bucket private but then nobody can serve the videos, including CloudFront — Block Public Access alone does not grant CloudFront access. Option B provides private network access to S3 from within a VPC, which is unrelated to controlling public access to the bucket.
Exam objective: SAA-C03 Task Statement 1.2: Design secure workloads and applications
Q3.A company sells premium training videos through CloudFront. Only paying customers should be able to view a video, and each customer's access should expire after 24 hours. Which solution meets these requirements?
Explanation: Signed URLs grant time-limited access to private content: the application issues each paying customer a URL that stops working after 24 hours, and anyone without a valid signed URL is denied. Option D controls access by geography, not by payment status. Option A only records access after the fact; it does not restrict anything. Option B is unmanageable and does not itself restrict access per customer.
Exam objective: SAA-C03 Task Statement 1.2: Design secure workloads and applications
Q4.A real-time multiplayer game runs in two AWS Regions. Players connect over the public internet and experience high latency and jitter during peak hours. The game traffic cannot be cached. Which AWS service BEST improves latency for the players?
Explanation: Global Accelerator is built for non-cacheable, latency-sensitive traffic: it gives the game static anycast IPs, brings player traffic onto the AWS global network at the nearest edge location, and routes it over AWS's private backbone to the best Region, with automatic failover if a Region fails. Option C is a CDN for cacheable content and cannot help real-time game traffic. Option A accelerates uploads to S3. Option D improves DNS routing decisions but the traffic still crosses the public internet.
Exam objective: SAA-C03 Task Statement 3.4: Determine high-performing and/or scalable network architectures
Q5.A company uses CloudFront to serve a website and needs to add a security header to every response and redirect all HTTP requests to HTTPS. The logic is simple and must run on every request with minimal added latency. Which solution is MOST appropriate?
Explanation: CloudFront Functions is designed for lightweight, high-volume viewer-trigger tasks like adding headers and redirecting HTTP to HTTPS, with minimal latency and cost. Option A would work but Lambda@Edge is heavier and more expensive than needed for simple request/response tweaks. Option B adds a server hop in front of the CDN, defeating the purpose of edge delivery. Option D filters malicious requests but cannot add headers or perform redirects.
Exam objective: SAA-C03 Task Statement 3.4: Determine high-performing and/or scalable network architectures
Q6.A website's images are cached by CloudFront with a TTL of 24 hours. The company publishes updated images with the same filenames and needs users to see the new images immediately. What is the BEST way to achieve this?
Explanation: A cache invalidation removes the specified objects from edge caches so the next request fetches the fresh version from the origin — the standard mechanism for urgent content updates. Option B leaves users seeing stale images for up to a day. Option D does not affect what CloudFront has already cached; the edge locations will keep serving the old copies until TTL expiry. Option C is a drastic rebuild that also changes the distribution domain name and takes time to deploy.
Exam objective: SAA-C03 Task Statement 3.4: Determine high-performing and/or scalable network architectures
Q7.A company wants to protect its CloudFront-served application from common web attacks such as SQL injection and cross-site scripting, and to block requests from known malicious IP addresses. Which AWS service should be integrated with the CloudFront distribution?
Explanation: AWS WAF is a web application firewall that inspects HTTP requests at CloudFront and blocks those matching rules for SQL injection, cross-site scripting, bad bots, and IP blocklists. Option C (Shield Standard) protects against DDoS attacks at the network layer but does not inspect application-layer request content. Option D is a threat-detection service that reports suspicious activity; it does not block web requests. Option A is a network firewall for VPC traffic, not for CloudFront distributions.
Exam objective: SAA-C03 Task Statement 1.2: Design secure workloads and applications
Q8.A company's application is deployed in two Regions behind an Application Load Balancer in each Region. The company wants users to be automatically routed to a healthy Region if one Region fails, using static IP addresses that do not change during failover. Which solution meets these requirements?
Explanation: Global Accelerator provides two static anycast IP addresses and continuously health-checks the endpoints in each Region, automatically shifting traffic to a healthy Region when one fails — with no DNS change needed, so failover is fast and the client IP addresses never change. Option D serves cached content and does not route application traffic between ALBs. Option C with simple routing returns a single answer with no health checking or failover. Option B connects two VPCs privately but does nothing for public user traffic routing.
Exam objective: SAA-C03 Task Statement 2.2: Design highly available and/or fault-tolerant architectures