CloudFront delivers web content through edge locations and retrieves missing content from an origin such as S3 or an HTTP server. These sections explain cache rules and freshness, origin and viewer access, origin failover, encryption, and functions that run during request processing.
CloudFront basics
Amazon CloudFront is AWS’s content delivery networkA content delivery network serves content through geographically distributed locations near viewers. (CDN): copies of content are served from edge locationsAn edge location is a CloudFront data center that serves content to viewers and caches copies of objects. close to users.
How it works
- A user requests content.
- The nearest edge location serves it if cached.
- Otherwise it fetches from the originAn origin is the server or bucket holding the original content that CloudFront retrieves., caches and returns it.
Exam cues
- If the question says low latencyLatency is the delay involved in delivering a request or response across the network. content delivery to global users, think CloudFront.
Remember
- Edge locations worldwide.
Trap: CloudFront caches content; Global Accelerator speeds up network paths without caching.
Da documentação da AWS (7)
- Amazon CloudFront speeds up delivery of static and dynamic web content by serving it from a worldwide network of edge locations.
- CloudFront serves content through edge locations and retrieves missing content from a configured origin.
- Origin access control authenticates CloudFront requests to an S3 bucket origin.
- The S3 bucket policy grants access to the CloudFront service principal cloudfront.amazonaws.com.
- An AWS:SourceArn condition scopes the S3 bucket policy grant to the distribution containing the origin.
- The read-only OAC bucket policy grants s3:GetObject on the bucket objects.
- Remove permissions that allow other users to read the S3 objects directly to prevent bypassing CloudFront.
Cache behaviors and policies
CloudFront delivers web content through edge locationsAn edge location is a CloudFront data center that serves content to viewers and caches copies of objects., which are servers that keep copies near viewersA viewer is the browser or other client that requests content from CloudFront., the clients requesting content. An originAn origin is the server or bucket holding the original content that CloudFront retrieves. holds the original content. A distributionA distribution is the CloudFront configuration describing its origins and how content is delivered. is the configuration that connects those origins to viewers; its cache behaviorsA cache behavior is a set of delivery rules applied to requests matching a URL path pattern. are ordered rules for different URL paths.
A cookieA cookie is a value stored by a client and sent with later requests. is a value stored by the client and sent with later requests. A query stringA query string is the part of a URL containing named request values after the path. carries named request values in the URL.
How it works
- CloudFront compares the requested URL path with behavior patterns in order. The first match selects the settings and origin or origin groupAn origin group pairs a primary and a secondary origin for eligible request failover., a primary and secondary pair used for failoverFailover sends an eligible request to a secondary origin after a configured primary failure.. The default
*behavior is last; cookies and query strings do not select a behavior. - The cache policy builds the cache keyA cache key is the identifier CloudFront uses to decide which stored response matches a request., the identifier used to find a stored response. Its default parts are the distribution domain and URL path. Add values that change the response, such as its language. The policy also sets time to liveTime to live is the duration for which a cached object remains valid before an origin freshness check. (TTL), how long cached content remains valid.
- A cache hitA cache hit occurs when a request matches a valid object already stored in a cache. means a valid stored response matches the key. CloudFront serves it without contacting the origin. On a miss, CloudFront forwards the key values and any extra values selected by the origin request policy.
| Policy | Controls | Typical use |
|---|---|---|
| Cache policy | Cache key and TTLs | Keep separate language variants |
| Origin request policy | Extra values sent to the origin | Forward tracing information |
For selected files or city-level rules, an application can check a geolocationGeolocation determines a requester's geographic location from information such as its IP address. service and issue a signed URL, a link carrying proof of permission. Use origin access control (OAC) with an S3 origin to prevent direct access around that check. Built-in geographic restrictions apply to the entire distribution at country level.
Exam cues
- If the question says a tracing header must reach the origin without creating extra cached copies, think origin request policy, because forwarding and cache identity are separate.
- If the question says authorize selected downloads by city, think application geolocation plus signed URLs and an S3 origin protected by OAC, because built-in geographic restrictions cover a whole distribution at country level.
Remember
- The first matching behavior wins; the default
*rule is last. - Cache key values are forwarded automatically.
- Standard logs (v2) go to S3, CloudWatch Logs or Data Firehose.
Trap: Adding
Cache-Controlwith a response headersAn HTTP header is a named value carried with a request or response to convey information such as caching instructions. policy changes viewer caching. It does not set CloudFront’s object TTL.
Da documentação da AWS (28)
- A distribution specifies the origins and settings CloudFront uses to deliver content.
- A cache behavior applies origin selection and delivery settings to a URL path pattern.
- CloudFront uses the first matching cache behavior in configured order.
- The default cache behavior uses the unchangeable path pattern * and is evaluated last.
- CloudFront does not consider cookies or query strings when matching a behavior path pattern.
- An earlier matching behavior without signed access allows access even if a later matching behavior requires signatures.
- Each cache behavior selects an origin or origin group.
- A cache key identifies a cached object; the default key includes the distribution domain name and URL path.
- Include request values that change the origin response in the cache key; irrelevant values can create duplicate cached objects.
- A cache policy selects headers, cookies and query strings for the cache key.
- A cache policy sets the minimum, default and maximum TTLs for cached content.
- A valid cached object with the same cache key can satisfy a request without contacting the origin.
- An origin request policy forwards additional request values without adding them to the cache key.
- Values included in the cache key by a cache policy are automatically included in origin requests.
- Cache-Control added by a response headers policy affects viewer caching, not CloudFront object caching.
- CloudFront geographic restrictions use a country allowlist or denylist for the entire distribution.
- CloudFront serves the requested content if it cannot determine the viewer country.
- For location rules finer than country or applying to selected files, an application can use a geolocation service and issue signed URLs to eligible viewers.
- AWS recommends an S3 origin with OAC to prevent direct origin access when using custom geolocation authorization.
- An origin group pairs a primary and a secondary origin for failover.
- A client stores cookie values and returns them with later requests.
- A URL query string carries named request values that a cache policy can include in the cache key.
- A CloudFront custom origin is any HTTP or HTTPS server with a publicly resolvable DNS name, hosted on AWS or elsewhere, such as an on-premises web server.
- CloudFront flat-rate pricing plans (Free, Pro, Business and Premium) bundle the CDN with AWS WAF, DDoS protection, a TLS certificate and S3 storage credits for one monthly price per distribution, with usage allowances and no overage charges.
- A default root object is the object CloudFront returns when a viewer requests the root URL of the distribution, which avoids exposing a listing of its contents.
- CloudFront can return a custom error page for chosen HTTP status codes; you pay standard charges for the error page instead of the requested object.
- A price class other than PriceClass_All limits which edge locations serve a distribution to lower cost; viewers in excluded regions may see slower performance.
- CloudFront standard logging (v2) can send access logs to Amazon S3, CloudWatch Logs or Data Firehose, with selectable fields.
TTL, stale content, and invalidation
CloudFront expiration settings control when a stored response needs another originAn origin is the server or bucket holding the original content that CloudFront retrieves. check. Time to liveTime to live is the duration for which a cached object remains valid before an origin freshness check. (TTL) is its freshness duration. A stale object has passed that duration but may still be usable during a refresh or an origin failure.
How it works
- CloudFront combines the cache policy’s minimum, default and maximum TTLs with the origin’s caching headers. It uses default TTL when both
Cache-ControlandExpiresare absent. - An origin
Cache-Controldirective is an instruction about caching.max-agesets freshness in seconds;s-maxagesets CloudFront freshness separately from the browser. When both appear, CloudFront usess-maxageand the browser usesmax-age. CloudFront applies its minimum and maximum TTL bounds.max-agetakes precedence overExpires, an expiration timestamp. - After expiry, CloudFront can check with the origin.
304 Not Modifiedmeans the cached version is still current;200 OKsupplies a new version. CloudFront can also evict, or remove, an infrequently used object before expiry to free space. - Origin stale directives allow continued delivery from an expired copy. Background refresh uses
stale-while-revalidate; origin failure usesstale-if-error. Each has a duration limit and remains bounded by maximum TTL. - To replace a file before expiry, invalidate its CloudFront path or publish a versioned file nameA versioned file name gives a new revision a different name so requests select that revision., a new name for a new revision. InvalidationInvalidation removes selected content from CloudFront edge caches before its normal expiry. removes edge copies; versioned names also avoid selecting old browser or proxy copies.
| Origin instruction | CloudFront effect |
|---|---|
max-age |
Freshness duration within TTL bounds |
s-maxage |
CloudFront freshness when browser freshness differs |
stale-while-revalidate |
Serve expired contentStale content is a cached object whose freshness duration has expired. while fetching a fresh copy |
stale-if-error |
Serve expired content when the origin is unreachable or returns an error between 500 and 600 |
Exam cues
- If the question says users see old assets after an invalidation, think versioned file names, because browser and proxy caches are outside that invalidation.
- If the question says serve content during origin failure, think
stale-if-error, because an expired cached copy can satisfy the request within its limits. - If the question says different browser and CloudFront freshness durations, think
max-agepluss-maxage, because the origin can set them separately.
Remember
- Without a cache policy, the initial default TTL is 24 hours; it is configurable.
- Minimum, default and maximum TTLs all set to 0 disable caching.
- Invalidation paths support
*. Versioned names avoid invalidation charges.
Trap: A minimum TTL above 0 overrides origin
private,no-cacheandno-storefor that minimum. Set minimum TTL to 0 to respect those directives.
Da documentação da AWS (19)
- TTL settings and origin Cache-Control or Expires headers determine how long cached objects remain valid.
- Default TTL applies when the origin provides no Cache-Control or Expires header.
- If no cache policy is used, the initial default TTL is 24 hours and can be changed.
- CloudFront bounds max-age or s-maxage freshness by the configured minimum and maximum TTLs.
- When both max-age and s-maxage are present, CloudFront uses s-maxage while browsers use max-age.
- Cache-Control max-age takes precedence over Expires when both are supplied.
- A minimum TTL greater than 0 makes CloudFront cache content for that minimum even with private, no-cache or no-store origin directives.
- With a minimum TTL of 0, CloudFront respects origin private, no-cache and no-store directives.
- Setting minimum, default and maximum TTLs all to 0 disables CloudFront caching.
- After a cached file expires, CloudFront can check the origin; an unchanged file returns 304 Not Modified and a changed file returns 200 OK with the new content.
- CloudFront can evict infrequently requested files before their expiration to make room for other files.
- stale-while-revalidate permits serving expired content while CloudFront fetches a fresh version in the background.
- stale-if-error permits serving expired content when the origin is unreachable or returns an error between 500 and 600.
- The stale directive duration and CloudFront maximum TTL limit stale serving; the object is unavailable after maximum TTL.
- stale-while-revalidate serving is limited by its directive duration and CloudFront maximum TTL.
- Invalidation removes a file from CloudFront edge caches before expiry; the next request fetches the latest origin version.
- AWS recommends versioned file names for frequent updates because they avoid invalidation charges and select a new file despite older copies in browser or proxy caches.
- CloudFront invalidation does not clear browser or corporate proxy caches.
- Invalidation paths support the * wildcard.
Origin access control
OriginAn origin is the server or bucket holding the original content that CloudFront retrieves. access control (OAC) lets CloudFront authenticate to an S3 bucket so the bucket can serve content through a distributionA distribution is the CloudFront configuration describing its origins and how content is delivered. without public read access. It protects the origin connection. Remove direct read permissions as well, so viewersA viewer is the browser or other client that requests content from CloudFront. cannot bypass CloudFront with S3 URLs.
How it works
- Use the regular S3 bucket origin. A static website endpoint is a custom origin, an HTTP server endpoint, and cannot use OAC or the legacy origin access identity (OAI).
- Set S3 Object OwnershipObject Ownership is an S3 setting controlling object ownership and the use of access control lists., the setting for who controls uploaded objects, to
Bucket owner enforced. If access control listsAn access control list assigns permissions for an S3 bucket or object. (ACLs), permission lists for buckets or objects, are required, AWS specifiesBucket owner preferred. - Grant the CloudFront service principalA service principal is the identity of an AWS service used in a resource policy., the AWS service identity
cloudfront.amazonaws.com, permission in the bucket policy. For reads, grants3:GetObjecton objects and useAWS:SourceArnto limit the grant to the distribution’s Amazon Resource NameAn ARN identifies an AWS resource such as the distribution named in an origin access policy. (ARN), its AWS resource identifier. - Attach OAC and select
Sign requests. CloudFront signs origin requests with Signature Version 4Signature Version 4 is AWS's request-signing format used by OAC to authenticate origin requests. (SigV4), AWS’s request authentication format, and uses HTTPSHTTPS is HTTP communication protected by TLS. to S3. - For server-side encryption with AWS KMSSSE-KMS encrypts objects at rest using an AWS KMS key. (SSE-KMS), encryption of stored objects using a KMS key, also grant the distribution key access in the KMS key policy.
| Signing behavior | API value | Effect |
|---|---|---|
| Sign requests | always |
Sign every request and use HTTPS to S3 |
| Do not sign requests | never |
Disable signing for origins using this OAC |
| Do not override authorization header | no-override |
Preserve viewer Authorization when supplied; otherwise sign |
For no-override, add Authorization to the cache policy on relevant S3 behaviors so CloudFront forwards the viewer’s header.
Exam cues
- If the question says keep S3 private while serving through CloudFront, think OAC plus a distribution-scoped bucket policy, because S3 must authorize CloudFront’s signed requests.
- If the question says OAC can read ordinary objects but needs access to SSE-KMS objects, think KMS key policy, because the distribution also needs permission to use the key.
- If the question says migrate from OAI without interrupting access, think allow both identities, switch to OAC, wait for full deployment, then remove OAI, because policy access must cover the transition.
Remember
- OAC supports all S3 Regions, SSE-KMS,
PUTandDELETE. alwaysis the recommended signing option.- The S3 website endpoint supports neither OAC nor OAI.
Trap: A bucket policy grant does not grant permission to a KMS key. SSE-KMS needs the key policy too.
The viewer requests content through the distribution.
When CloudFront requests the object from S3, OAC signs the request; the bucket policy grants the distribution access.
Detalhes das caixas (3)
- Viewer
Requests content through CloudFront.
- CloudFront
Signs S3 requests with Signature Version 4 and uses HTTPS.
- Private S3
The bucket policy permits the CloudFront service principal for the distribution ARN.
Da documentação da AWS (20)
- OAC supports S3 buckets in all AWS Regions.
- OAC supports S3 objects encrypted with SSE-KMS.
- OAC supports PUT and DELETE requests to S3.
- AWS recommends OAC over legacy origin access identity (OAI) for S3 origins.
- An S3 website endpoint is a custom origin and supports neither OAC nor OAI.
- For S3 with OAC, use Bucket owner enforced Object Ownership; if ACLs are required, use Bucket owner preferred.
- The read-only OAC bucket policy grants s3:GetObject on the bucket objects.
- OAC signs origin requests using Signature Version 4 (sigv4).
- The recommended Sign requests option, API value always, signs every origin request.
- With OAC set to always sign, CloudFront always uses HTTPS to S3.
- The Do not sign requests option, API value never, disables signing for origins sharing the OAC.
- Do not override authorization header, API value no-override, preserves viewer Authorization when supplied and otherwise signs the request.
- With no-override, add Authorization to the cache policy of relevant S3 behaviors to pass the viewer header through.
- SSE-KMS objects also require a KMS key policy permitting the CloudFront distribution to use the key.
- Before migrating from OAI to OAC, update the bucket policy to allow both the OAI and the distribution using OAC.
- After switching the distribution to OAC and waiting for full deployment, remove the old OAI bucket policy grant.
- An Amazon Resource Name (ARN) uniquely identifies an AWS resource.
- S3 Object Ownership controls ownership of uploaded objects and enables or disables access control lists.
- The CloudFront managed prefix list holds the IP ranges of CloudFront origin-facing servers; referencing it in a security group lets only CloudFront reach an origin such as an ALB or EC2 instance.
- Origin access control can also restrict access to a Lambda function URL origin, so only CloudFront can invoke the URL.
Origin failover
CloudFront originAn origin is the server or bucket holding the original content that CloudFront retrieves. failoverFailover sends an eligible request to a secondary origin after a configured primary failure. retries eligible requests on a secondary origin when the primary fails. An origin groupAn origin group pairs a primary and a secondary origin for eligible request failover. is the pair of origins attached to a cache behaviorA cache behavior is a set of delivery rules applied to requests matching a URL path pattern.. This gives cached content a second place to be retrieved from during an origin outage.
How it works
- Add the primary and secondary origins, create an origin group, and select that group in the cache behavior. For an S3 site spanning Regions, use Cross-Region ReplicationReplication copies objects between buckets, including buckets in different Regions. to copy new and updated objects asynchronously, meaning the copy happens after the source write. Use S3 Batch Replication for objects that existed before live replication was configured.
- A cache hitA cache hit occurs when a request matches a valid object already stored in a cache. returns stored content. With default origin selection, a cache missA cache miss occurs when the requested object is not available in the cache and must be retrieved. first contacts the primary, even when an earlier request failed over.
- CloudFront evaluates the configured failure status codes. A connection failure qualifies when
503is selected; a response timeoutA response timeout limits how long CloudFront waits for an origin response. qualifies when504is selected. - For
GET,HEADor eligibleOPTIONS, CloudFront sends the request to the secondary.OPTIONSmust be included in cached HTTP methods. Other methods do not fail over. - Tune connection attempts and timeouts if connection failures must move to the secondary faster. For custom origins, the origin response timeout, the wait for the origin’s response, can also be adjusted.
| Setting | Range | Default |
|---|---|---|
| Connection timeoutA connection timeout limits how long CloudFront waits to establish an origin connection. | 1 to 10 seconds | 10 seconds |
| Connection attempts | 1 to 3 | 3 |
| Response timeout | 1 to 120 seconds | 30 seconds |
Exam cues
- If the question says an S3 site needs read availability across Regions, think replicated buckets plus an origin group, because the secondary must have the objects that CloudFront requests.
- If the question says shorten connection failure recovery, think fewer attempts or a shorter connection timeout, because default connection attempts can take up to 30 seconds.
- If the question says CloudFront origin failover already covers two Regions, think a plain Route 53 alias to the distributionA distribution is the CloudFront configuration describing its origins and how content is delivered., because the origin group handles failover.
Remember
- Failover codes:
400,403,404,416,429,500,502,503,504. - With default origin selection, each cache miss tries the primary before failover.
- An origin-request Lambda@Edge function can run twice during failover, once for each origin.
Trap: An origin group does not retry
POSTorPUTon the secondary. Replicating S3 objects does not change the eligible request methods.
Trap: The default 30 seconds describes connection attempts. It is not a fixed recovery time for every failure; response timeout settings also affect the wait.
CloudFront finds the matching cache behavior and checks for cached content.
With default origin selection, a cache miss goes to the primary origin.
A configured failure sends GET, HEAD or cached OPTIONS to the secondary origin.
Detalhes das caixas (4)
- Viewer
Requests an object from CloudFront.
- CloudFront
A hit returns cached content. A miss uses the origin group.
- Primary origin
With default origin selection, each cache miss tries the primary before failover.
- Secondary origin
Prepare the content here too, such as with S3 Cross-Region Replication.
Da documentação da AWS (17)
- An origin group contains a primary and a secondary origin and must be selected by a cache behavior.
- CloudFront serves a cache hit without contacting the origin group.
- With default origin selection, each cache miss goes to the primary before failover, even if an earlier request used the secondary.
- Selectable failover status codes are 400, 403, 404, 416, 429, 500, 502, 503 and 504.
- Failure to connect to the primary triggers failover when 503 is selected.
- A primary response timeout triggers failover when 504 is selected.
- Origin failover supports only GET, HEAD and OPTIONS, not POST or PUT.
- OPTIONS requests fail over only when OPTIONS is included in cached HTTP methods.
- Origin connection timeout is 1 to 10 seconds, with a default of 10 seconds.
- Origin connection attempts are 1 to 3, with a default of 3.
- Default connection attempts can take as long as 30 seconds before failover to the secondary.
- The origin response timeout defaults to 30 seconds and can be set from 1 to 120 seconds; it can also be adjusted for faster failover with custom origins.
- S3 Cross-Region Replication asynchronously copies new and updated objects to a bucket in another Region.
- S3 live replication does not copy objects that predate its configuration.
- S3 Batch Replication can copy existing objects.
- An origin-request Lambda@Edge function can run for both the primary and secondary during one viewer request.
- Route 53 points a domain at a CloudFront distribution with an alias record, an A record plus an AAAA record when IPv6 is enabled.
Origin Shield
OriginAn origin is the server or bucket holding the original content that CloudFront retrieves. Shield is an extra CloudFront cache between regional edge caches and an origin. Regional edge caches are intermediate stores that serve misses from nearby edge locationsAn edge location is a CloudFront data center that serves content to viewers and caches copies of objects.. Origin Shield lets requests from different regions share another cached copy and reduces duplicate work at the origin.
How it works
- Enable Origin Shield for each origin that needs it. Choose the AWS Region with the lowest latencyLatency is the delay involved in delivering a request or response across the network., the shortest network delay, to that origin. The origin can be inside or outside AWS.
- Requests that miss regional edge caches can converge on Origin Shield. A Shield cache hitA cache hit occurs when a request matches a valid object already stored in a cache. avoids another origin request.
- If the object is missing, Origin Shield can consolidate simultaneous requests for the same object into as few as one origin fetch. This helps with costly work such as image processing or packaging live video.
- In a multi-CDN design, where several content delivery networksA content delivery network serves content through geographically distributed locations near viewers. serve viewersA viewer is the browser or other client that requests content from CloudFront., use the CloudFront distributionA distribution is the CloudFront configuration describing its origins and how content is delivered. as the origin for the other CDNs so they can share this cache.
Origin Shield is also compatible with origin groupsAn origin group pairs a primary and a secondary origin for eligible request failover.. When enabled on both origins, requests use the primary origin’s Shield; after failoverFailover sends an eligible request to a secondary origin after a configured primary failure., they use the secondary’s Shield. Origin-facing Lambda@Edge triggersA trigger associates a Lambda@Edge function with an event on a CloudFront cache behavior. run in the Shield Region, while viewer-facing triggers are unaffected.
Exam cues
- If the question says viewers in many regions cause duplicate origin fetches, think Origin Shield, because regional caches can share another cached copy and consolidate misses.
- If the question says choose a Shield Region for an on-premises origin, think lowest latency to the origin, because Shield supports origins outside AWS.
- If the question says several CDNs overwhelm a packaging origin, think CloudFront with Origin Shield as their origin, because this brings their requests through a shared cache.
Remember
- Configure Origin Shield per origin.
- Origin Shield adds charges.
- gRPCgRPC is a protocol for calling remote application functions., a protocol for calling remote application functions, bypasses Origin Shield.
Trap: Dynamic content, poorly cacheable responses and infrequent requests may gain little from another cache. Origin Shield still adds charges.
A regional edge cache misses and requests the object through Origin Shield.
Requests from other regional edge caches can use the same Origin Shield cache.
On a Shield miss, simultaneous requests for the same object can be consolidated into one origin request.
Detalhes das caixas (4)
- Regional cache A
An intermediate CloudFront cache serving edge misses.
- Regional cache B
Another geographic area can request the same object.
- Origin Shield
A hit avoids the origin. Simultaneous misses for the same object can be consolidated.
- Origin
Receives fewer duplicate requests for cacheable content.
Da documentação da AWS (14)
- Origin Shield adds a CloudFront caching layer between regional edge caches and the origin.
- Regional edge caches are an intermediate cache layer that serves edge misses and consolidates requests from nearby geographic areas.
- Origin Shield consolidates simultaneous misses for the same object, potentially reducing them to one origin request.
- Choose the Origin Shield Region with the lowest latency to the origin.
- Origin Shield is configured separately for each origin in a distribution.
- Origin Shield supports origins inside and outside AWS.
- Using a CloudFront distribution with Origin Shield as the origin for other CDNs can reduce duplicate requests to the content origin.
- Origin Shield can benefit globally distributed viewers and origins that perform image processing or live video packaging.
- Content with low cacheability, infrequent requests or dynamic requests proxied to the origin may be a poor fit for Origin Shield.
- Origin Shield adds charges.
- gRPC requests bypass Origin Shield even when it is enabled on the distribution.
- When enabled for both origins in an origin group, requests use the primary origin's Origin Shield and then the secondary origin's Origin Shield if failover occurs.
- Origin-facing Lambda@Edge triggers run in the Region where Origin Shield is enabled; viewer-facing triggers are unaffected.
- gRPC is a framework for remote procedure calls, which invoke application functions on a remote system.
Signed URLs and cookies
Signed URLs and signed cookies let CloudFront enforce an application’s decision about who may retrieve private content. A signatureA signature is proof generated with a private key and validated with the matching public key. is proof generated with a private key and checked with its public key. The application grants access; CloudFront checks that grant before delivering protected content.
How it works
- Configure a trusted key groupA trusted key group contains public keys CloudFront accepts for validating signed URLs or cookies., a collection of public keys accepted for signed access, on the relevant cache behaviorA cache behavior is a set of delivery rules applied to requests matching a URL path pattern., the rule for that URL path. AWS recommends key groups because keys can be managed through APIs and IAM permissions without the account root user.
- The application determines whether a viewerA viewer is the browser or other client that requests content from CloudFront. may access the content. It uses its private key to sign a URL or cookieA cookie is a value stored by a client and sent with later requests. policy, the rules that set the permitted resource and access period.
- For a signed URL, the viewer requests the returned link. For signed cookies, the application sends three
Set-Cookieheaders; the client stores these values and returns them with content requests. A cookie is a value a client stores and sends with later requests. - CloudFront uses the public key to check the signature and evaluates the policy. Once access is permitted, it serves a cached copy or retrieves the file from the originAn origin is the server or bucket holding the original content that CloudFront retrieves..
- Restrict the origin separately. For S3, use origin access control (OAC); for a custom HTTP server, require custom headers so direct requests cannot bypass CloudFront.
Use signed URLs for individual downloads or clients that cannot store cookies. Use signed cookies for access to many files while preserving existing URLs.
| Policy constraint | Canned policyA canned signed access policy specifies an expiry without the optional start-time and IP restrictions of a custom policy. | Custom policyA custom signed access policy can add start-time and IP restrictions and cover multiple files with a wildcard resource. |
|---|---|---|
| Expiration time | Yes | Yes |
| Optional start time | No | Yes |
| Optional client IP range | No | Yes |
| Wildcard resource for multiple files | No | Yes |
Exam cues
- If the question says protect many media files without changing URLs, think signed cookies, because one grant can cover multiple restricted files.
- If the question says a download client cannot use cookies, think signed URL, because the access information travels in the link.
- If the question says access starts at a future time or is limited to an IP range, think custom policy, because a canned policy lacks those constraints.
Remember
- The application signs with the private key; CloudFront checks with the public key.
- Signed cookies require three
Set-Cookieheaders. - A signed URL takes precedence over signed cookies when both are present.
Trap: Expiry is checked at request time. A download started before expiry can finish, but a new retry or range requestA range request asks for part of a file instead of the complete object. after expiry fails.
Trap: Allowed
OPTIONSrequests do not require a signature. The origin must not return protected content for that method.
The application authorizes the viewer and issues a signed URL or signed cookies.
CloudFront validates the signature and access policy for the content request.
After a successful check, a cache hit is served or CloudFront fetches from the restricted origin.
Detalhes das caixas (4)
- Application
Determines whether the viewer may access the requested content.
- Viewer
Receives the signed URL or cookies and requests content.
- CloudFront
Validates the signature and policy before serving protected content.
- Private origin
Origin access restrictions prevent direct reads around CloudFront.
Da documentação da AWS (23)
- CloudFront signed URLs and signed cookies control viewer access to private content.
- Use signed URLs for individual files or clients that do not support cookies.
- Use signed cookies for multiple restricted files or to preserve existing URLs.
- AWS recommends trusted key groups to specify which public keys CloudFront accepts for signed access.
- Trusted key groups allow API and IAM-based key management without using the AWS account root user.
- The application determines whether a viewer is entitled to content and returns signed URLs or signed cookies.
- The application signs CloudFront URLs with a private key.
- CloudFront validates a signed URL with the corresponding public key in a trusted key group.
- CloudFront validates the signature and access policy before serving protected content from cache or fetching it from the origin.
- The application sends three Set-Cookie headers to set the values required for CloudFront signed cookies.
- Both canned and custom signed access policies specify when access ends.
- A custom policy can optionally set the date and time when access starts.
- A custom policy can optionally restrict access by client IP address or range.
- A custom policy can use a wildcard resource to cover multiple files.
- Signed URLs do not prevent direct origin access.
- OAC and removal of direct S3 read permissions prevent viewers from bypassing CloudFront via S3 URLs.
- A custom HTTP origin can require custom headers to restrict direct access around CloudFront.
- CloudFront checks signed URL expiry at the time of each HTTP request.
- A download begun before signed URL expiry can finish after expiry.
- A retry or range request begun after signed URL expiry fails.
- When a request has both a signed URL and signed cookies, CloudFront uses the signed URL alone to decide access.
- CloudFront does not require a signature for allowed OPTIONS requests on behaviors requiring signed access, so the origin must not return protected content to OPTIONS.
- A client stores cookie values and returns them in a Cookie header with later requests.
TLS and field-level encryption
CloudFront uses Transport Layer SecurityTLS protects data while it travels over an HTTPS connection. (TLS) to protect HTTPSHTTPS is HTTP communication protected by TLS. connections. The viewerA viewer is the browser or other client that requests content from CloudFront. connection and the custom-origin connection have separate settings. Field-level encryption protects selected form values beyond those connections so they stay encrypted inside the application until the component with the private key reads them.
How it works
- For an alternate domain nameAn alternate domain name is a custom domain associated with a CloudFront distribution., your custom name for the distributionA distribution is the CloudFront configuration describing its origins and how content is delivered., request or import the viewer certificate in ACM in
us-east-1. Its subject alternative nameA subject alternative name is a certificate field listing the domain names the certificate covers. (SAN) field, the list of names a certificate covers, must include an exact match or a wildcard at the same domain level. - With Server Name IndicationSNI lets a client include the requested domain in its TLS handshake so CloudFront can select the certificate. (SNI), the viewer includes the domain in its TLS ClientHelloClientHello is the opening TLS negotiation message in which an SNI client supplies the requested domain., the message that starts negotiation. CloudFront selects the matching distribution and certificate without dedicated IP addresses. Dedicated IP HTTPS supports clients without SNI and adds a monthly charge.
- Set the viewer protocol policy to redirect HTTP or reject it. Choose the viewer security policy for the minimum TLS version and ciphersA cipher is an encryption algorithm allowed by a CloudFront TLS security policy., the encryption algorithms allowed on the connection.
- Set the originAn origin is the server or bucket holding the original content that CloudFront retrieves. protocol policy separately. For HTTPS, the origin certificate must come from a trusted certificate authorityA certificate authority issues certificates used to establish trust in a TLS endpoint. (CA), an issuer CloudFront accepts. Its name must match the origin domain or forwarded
Hostdomain. Invalid certificates or name mismatches can produce502 Bad Gateway. - For field-level encryption, upload the public key. A profile selects the POST fields; a configuration chooses profiles and attaches to a cache behaviorA cache behavior is a set of delivery rules applied to requests matching a URL path pattern.. CloudFront encrypts those fields, and the authorized application uses the private key to decrypt them.
| Custom-origin protocol policy | Connection used |
|---|---|
| HTTP only | HTTP |
| HTTPS only | HTTPS |
| Match viewer | The viewer request’s protocol |
Field-level encryption supports up to 10 fields per request. Require viewer Redirect HTTP to HTTPS or HTTPS only, origin Match viewer or HTTPS only, and allow GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE on the behavior.
Exam cues
- If the question says a custom domain cannot use its ACM certificate, think
us-east-1and SAN coverage, because those are requirements for the viewer certificate. - If the question says modern clients need custom-domain HTTPS without dedicated addresses, think SNI, because the requested domain selects the certificate.
- If the question says intermediate application components must not see selected form fields, think field-level encryption, because TLS alone protects connections and those fields must remain encrypted through processing.
Remember
HTTPS onlyviewer policy rejects HTTP with403.- Redirect mode uses
301for GET and HEAD; for POST, PUT, DELETE, OPTIONS and PATCH over HTTP 1.1 or later it uses307, preserving method and body. Those methods below HTTP 1.1 get403. - The viewer ACM certificate belongs in
us-east-1; an Elastic Load Balancing origin uses its own regional certificate. Provision it in the Region where the load balancer uses it. - Field-level encryption supports at most 10 fields per request.
- Any DNS provider can point an alternate domain name at the distribution.
Trap: Viewer HTTPS does not configure custom-origin HTTPS. An S3 website endpoint cannot use HTTPS on the origin connection.
Trap: Field-level encryption encrypts named POST fields. It cannot encrypt the entire request.
The viewer submits selected form fields over HTTPS.
CloudFront encrypts the configured fields with the public key and forwards the request over HTTPS.
The fields remain encrypted until the application holding the private key decrypts them.
Detalhes das caixas (4)
- Viewer
Submits a form using HTTPS.
- CloudFront
Uses the configured public key to encrypt selected POST fields.
- Web tier
Intermediate application components receive fields that remain encrypted.
- Authorized app
Only the component holding the corresponding private key can decrypt the fields.
Da documentação da AWS (32)
- Viewer HTTPS and HTTPS from CloudFront to a custom origin are configured separately.
- An ACM certificate used between viewers and CloudFront must be requested or imported in us-east-1.
- For an Elastic Load Balancing origin, its ACM certificate can be requested or imported in any AWS Region.
- The viewer certificate SAN must cover each alternate domain name exactly or with a wildcard at the same domain level.
- Redirect HTTP to HTTPS redirects viewer GET and HEAD requests with status 301.
- With Redirect HTTP to HTTPS, HTTP 1.1 or later POST, PUT, DELETE, OPTIONS and PATCH requests receive 307 with the same method and body preserved.
- For those non-GET and non-HEAD methods with a request protocol below HTTP 1.1, Redirect HTTP to HTTPS returns 403.
- HTTPS only viewer protocol policy rejects HTTP requests with status 403.
- A CloudFront viewer security policy specifies the minimum TLS version and allowed encryption ciphers.
- HTTP only origin protocol policy sends custom-origin requests over HTTP.
- HTTPS only origin protocol policy sends custom-origin requests over HTTPS.
- Match viewer origin protocol policy uses the viewer request protocol for the custom-origin connection.
- A custom origin certificate must match the configured origin domain or the forwarded Host header domain.
- CloudFront requires a certificate from a trusted CA for HTTPS to a custom origin.
- An invalid, expired or self-signed custom-origin certificate causes CloudFront to return 502.
- An origin certificate that does not match the origin domain can cause CloudFront to return 502 Bad Gateway.
- S3 static website endpoints do not support HTTPS from CloudFront to the origin.
- With Server Name Indication (SNI), the client includes the requested domain in the TLS ClientHello; CloudFront selects the matching distribution and certificate without dedicated IPs.
- Dedicated IP HTTPS is an alternative for clients lacking SNI and adds a monthly charge.
- Field-level encryption encrypts selected POST fields at the edge with a public key; only applications holding the corresponding private key can decrypt them.
- Field-level encryption supports up to 10 data fields per request.
- Field-level encryption requires selected fields and cannot encrypt the entire request.
- A field-level encryption profile selects which fields to encrypt.
- A field-level encryption configuration chooses profiles and is linked to a cache behavior.
- Field-level encryption requires viewer protocol policy Redirect HTTP to HTTPS or HTTPS only.
- Field-level encryption requires allowing GET, HEAD, OPTIONS, PUT, POST, PATCH and DELETE on the cache behavior.
- Field-level encryption requires origin protocol policy Match viewer or HTTPS only.
- Encrypted fields remain encrypted through intermediate application components until an authorized component decrypts them.
- ACM certificates are regional resources; an Elastic Load Balancing certificate must be provisioned separately in each Region where it is used.
- Chunked transfer encoding sends a message body in chunks.
- HTTPS protects connections, while field-level encryption keeps selected data encrypted during application processing.
- An alternate domain name for a CloudFront distribution is routed by its DNS service, which can be Route 53 with an alias record or another DNS provider pointing to the distribution domain name.
CloudFront Functions and Lambda@Edge
CloudFront Functions and Lambda@Edge run code at CloudFront events so a request or response can be changed during delivery. A triggerA trigger associates a Lambda@Edge function with an event on a CloudFront cache behavior. is an association between a function and an event on a cache behaviorA cache behavior is a set of delivery rules applied to requests matching a URL path pattern., the rule for a set of URL paths. Event placement decides whether the function also runs for cached content.
How it works
- On the normal request path, the viewerA viewer is the browser or other client that requests content from CloudFront. request event happens before cache lookup. Use this point to normalize, or make consistent, request values that form a cache keyA cache key is the identifier CloudFront uses to decide which stored response matches a request., the identifier for stored content.
- A cache hitA cache hit occurs when a request matches a valid object already stored in a cache. skips originAn origin is the server or bucket holding the original content that CloudFront retrieves. events. When CloudFront forwards to the origin, the origin request event can change the request or call an external service. An authorization tokenAn authorization token is request information a function inspects to decide whether access is permitted. is information sent by a client to prove access; Lambda@Edge can inspect it or call an identity service to confirm credentials.
- An origin response event runs after the origin replies and before caching. It also runs for origin errors, but not for a response generated by an origin-request function.
- The viewer response event runs before delivery for normal cached and origin responses. Lambda@Edge skips it for origin responses of
400or higher, custom error pages, viewer-request-generated responses and automatic HTTP-to-HTTPS redirects. Viewer request is also skipped for custom error-page fetches and automatic redirects. - To deploy Lambda@Edge, create the function in
us-east-1, publish a numbered version and associate it with the behavior event. AWS replicates it globally; it processes events after the distributionA distribution is the CloudFront configuration describing its origins and how content is delivered. deploys.
The following table compares HTTP request and response functions.
| Capability | CloudFront Functions | Lambda@Edge |
|---|---|---|
| Events | Viewer request and viewer response | Viewer and origin request and response |
| Runtime | JavaScript | Node.js or Python |
| Execution duration | Submillisecond | Up to 30 seconds |
| Network, file system, request bodyThe request body is the data sent with a request that a Lambda@Edge function can inspect or replace. | No access | Access supported |
To expose the request body, the data sent with a request, to Lambda@Edge, select Include Body. CloudFront exposes it as base64Base64 is an encoding that represents binary data as text., a text encoding for binary data, and truncates it at 40 KB for viewer request or 1 MB for origin request. Reading without replacement still forwards the full original body to the origin.
Exam cues
- If the question says lightweight redirects or consistent cache keys, think CloudFront Functions at viewer request, because these are supported uses before cache lookup.
- If the question says call an external service only before origin forwarding, think Lambda@Edge origin request, because CloudFront Functions has no network access and origin request skips hits.
- If the question says consult an identity service before serving cached private content, think Lambda@Edge viewer request, because origin-request authorization never sees cache hits.
Remember
- Lambda@Edge uses
us-east-1and a numbered version, not$LATESTor an alias. - An origin-request function can run twice during origin-group failoverFailover sends an eligible request to a secondary origin after a configured primary failure..
- Lambda@Edge viewer-response functions cannot change the HTTP status code.
Trap: Origin-request authentication protects origin forwarding. It does not run when CloudFront serves a cache hit.
The viewer request event runs before cache lookup on the normal request path.
CloudFront checks its cache.
A miss that is forwarded to the origin invokes the origin request event.
CloudFront sends the request to the origin.
The origin response invokes the origin response event.
CloudFront can cache the response after the origin response event.
The normal response path invokes the viewer response event.
CloudFront returns the response; a cache hit skips the origin-facing path.
Detalhes das caixas (8)
- Viewer
Requests content and receives a response.
- Viewer request
Use this event when a check must also protect cache hits.
- Cache lookup
A hit skips origin-facing events.
- Origin request
Can call an external service before the origin request.
- Origin
Receives the request and returns its response.
- Origin response
Runs after an origin response, including an origin error.
- Cache response
The origin response event runs before the response is cached.
- Viewer response
Runs on the normal response path for hits and misses; see the exceptions in the text.
Da documentação da AWS (35)
- CloudFront Functions and Lambda@Edge run code in response to CloudFront request and response events.
- For HTTP request and response customization, CloudFront Functions supports viewer request and viewer response events.
- CloudFront Functions uses JavaScript and is designed for submillisecond execution.
- CloudFront Functions for HTTP delivery cannot make network calls.
- CloudFront Functions for HTTP delivery has no file system access.
- CloudFront Functions for HTTP delivery has no request body access.
- CloudFront Functions can normalize cache keys, modify headers, redirect or rewrite URLs, and validate hashed authorization tokens.
- Lambda@Edge supports viewer request, origin request, origin response and viewer response events.
- Lambda@Edge supports Node.js and Python.
- Lambda@Edge allows up to 30 seconds for viewer and origin events.
- Lambda@Edge supports network access.
- Lambda@Edge supports file system access.
- Lambda@Edge supports request body access.
- A viewer-request Lambda@Edge trigger runs before the cache lookup, except for custom error-page fetches and automatic HTTP-to-HTTPS redirects.
- An origin-request Lambda@Edge trigger runs when CloudFront forwards to the origin and does not run on cache hits.
- An origin-response Lambda@Edge trigger runs after an origin response and before caching, including origin error responses; it does not run for a response generated by an origin-request function.
- A viewer-response Lambda@Edge trigger runs before delivery for cached and origin responses, with documented exceptions.
- A viewer-response Lambda@Edge trigger is skipped for origin responses of 400 or higher, custom error pages, viewer-request-generated responses and automatic HTTP-to-HTTPS redirects.
- A Lambda@Edge function must be in US East (N. Virginia), us-east-1.
- Lambda@Edge requires a numbered function version and does not accept $LATEST or aliases.
- Associate a numbered Lambda@Edge version with a cache behavior event.
- AWS replicates a deployed Lambda@Edge function globally.
- A Lambda@Edge function processes associated events after the distribution deployment completes.
- Lambda@Edge can inspect headers or authorization tokens before origin forwarding and make external network calls to confirm user credentials.
- An origin-request Lambda@Edge function can be invoked twice for one viewer request during origin-group failover.
- Select Include Body to expose a request body to a Lambda@Edge function.
- CloudFront base64-encodes the request body before exposing it to Lambda@Edge.
- The request body exposed to a viewer-request Lambda@Edge function is truncated at 40 KB.
- The request body exposed to an origin-request Lambda@Edge function is truncated at 1 MB.
- If a Lambda@Edge function reads but does not replace the request body, CloudFront forwards the full original body to the origin.
- A Lambda@Edge viewer-response function cannot modify the HTTP response status code.
- A viewer-request CloudFront Function executes before the cache lookup.
- Base64 encoding represents binary data as text.
- CloudFront added Connection Functions for viewer mutual TLS in November 2025.
- Mutual TLS extends TLS authentication so both client and server prove their identities using certificates.
Distribution design choices
CloudFront offers distributionA distribution is the CloudFront configuration describing its origins and how content is delivered. settings for access, originAn origin is the server or bucket holding the original content that CloudFront retrieves. connectivity and request handling. These choices help control who can connect, where requests go and which responses can be cached.
How it works
- Use a country allowlistAn allowlist identifies the countries permitted to access a distribution. or denylistA denylist identifies the countries blocked from accessing a distribution. to restrict an entire distribution. For geography combined with other conditions, use AWS WAF geo match.
- For custom clientA viewer is the browser or other client that requests content from CloudFront. certificate checks during the TLSTLS protects data while it travels over an HTTPS connection. handshake, use a CloudFront Connection Function. It allows or denies the connection and cannot modify HTTP requests or responses.
- For an origin in a private subnet, use a VPC origin. It supports Application Load Balancers, Network Load Balancers and EC2 instances, with CloudFront as the single entry point and no public access needed at the origin.
- When all HTTP methods are allowed, CloudFront forwards uploads and other requests using
PUT,POST,PATCHandDELETEto the origin over the edge network. It caches onlyGET,HEADand optionallyOPTIONSresponses. See HTTP methods.
Exam cues
- If the question says restrict a whole distribution by country, think CloudFront geographic restrictions, because they use a distribution-wide allowlist or denylist.
- If the question says combine geography with other conditions, think AWS WAF geo match, because CloudFront geo-blocked requests do not reach WAF.
- If the question says check client certificates during connection establishment, think Connection Function, because it can allow or deny the TLS connection.
- If the question says serve an internal load balancer without a public origin, think VPC origin, because CloudFront can reach it in a private subnet.
- If the question says upload through CloudFront, think allow all HTTP methods, because
PUTandPOSTare forwarded to the origin.
Remember
- CloudFront caches
GETandHEADresponses and can cacheOPTIONSresponses, but does not cache responses to the other methods. - Data transfer from AWS origins to CloudFront, such as from S3 or an Application Load Balancer, is not charged.
Trap: A CloudFront geographic restriction blocks requests before AWS WAF receives them. Use WAF geo match when geography must be combined with other conditions.
Da documentação da AWS (8)
- CloudFront geographic restrictions use a country allowlist or denylist for the entire distribution.
- CloudFront geographic restrictions do not forward blocked requests to AWS WAF; use WAF geo match to combine geography with other conditions.
- When a distribution allows all HTTP methods, CloudFront forwards PUT, POST, PATCH and DELETE requests to the origin, so uploads also travel over the AWS edge network; it caches only GET, HEAD and optionally OPTIONS responses.
- Connection Functions are a type of CloudFront Functions for custom client certificate checks during the TLS handshake.
- A CloudFront Connection Function allows or denies a TLS connection.
- CloudFront Connection Functions cannot modify HTTP requests or responses.
- CloudFront VPC origins deliver content from Application Load Balancers, Network Load Balancers and EC2 instances in private subnets, so CloudFront becomes the single entry point and the origin needs no public access.
- Data transfer from AWS origins, such as S3 or an ALB, to CloudFront is not charged.
Flashcards
Nada para revisar aqui agora. Escolha outros tópicos ou outro filtro.
·
Todos os 58 flashcards em lista
How do Amazon CloudFront edge locations benefit users around the world?
They speed up delivery of static and dynamic web content through a worldwide network.
A website needs to serve cached content from locations close to viewers. Which AWS service fits?
Amazon CloudFront delivers content through edge locations and retrieves missing content from the configured origin.
A team serves content from S3 through CloudFront and must prevent direct public bucket reads. What should it configure?
Use OAC with the regular S3 bucket origin. Grant cloudfront.amazonaws.com s3:GetObject in the bucket policy, scoped by AWS:SourceArn to the distribution. Remove direct public read permissions.
What decides which CloudFront origin and settings handle a request?
The first matching cache behavior in list order. The default * behavior is last. An earlier public match can bypass a later matching behavior that requires signed access.
What is a CloudFront cache key, and how does a cache policy control it?
The identifier for a cached object. The default includes the distribution domain and URL path. A cache policy selects additional headers, cookies and query strings, and sets TTLs.
A CloudFront origin needs a tracing header that does not change its response. How can the team forward it without splitting the cache?
Use an origin request policy. It forwards additional values without changing the cache key; values already in the key are forwarded automatically.
A CloudFront origin returns different pages by language and records a tracing header. How should the team choose cache and origin request policy inputs?
Include the response-changing language value in the cache policy. Forward the tracing header with an origin request policy so it does not create duplicate cached objects.
A CloudFront application licenses only selected files to users in approved cities. How should it authorize downloads?
Have the application evaluate a geolocation service result and issue a signed URL to eligible users. For an S3 origin, use OAC to prevent direct bucket access. Built-in geographic restrictions apply to whole distributions at country level.
A dynamic site must stay in an on-premises data center in the US but load faster for new users in Asia within days. What fits?
A CloudFront distribution with a custom origin that points to the on-premises web servers. A custom origin can be any publicly resolvable HTTP server.
A company serves viewers mostly in North America and Europe and wants to lower CloudFront delivery costs, accepting slower access elsewhere. Which setting fits?
A cheaper price class (such as Price Class 100). It limits the edge locations used; viewers in excluded regions may see more latency.
A CloudFront origin returns different content for different query values. How should the team prevent those responses from sharing the same cache key?
Use a cache policy to include the relevant query strings in the cache key.
Amazon CloudFront access logs must stream into Amazon Data Firehose instead of S3. Is that supported?
Yes. Standard logging (v2) can deliver to S3, CloudWatch Logs or Data Firehose.
How long does CloudFront cache an object with neither Cache-Control nor Expires in the origin response?
For the configured default TTL. If no cache policy is used, the initial default is 24 hours, but it can be changed.
A CloudFront origin sends Cache-Control: private, but the response is cached. Which cache setting should the team inspect?
Minimum TTL. A value above 0 makes CloudFront cache for at least that minimum even with private, no-cache or no-store. With a minimum of 0, it respects those directives.
Which CloudFront origin response directives allow serving stale content during background refresh or origin errors?
Use stale-while-revalidate for background refresh and stale-if-error for an unreachable origin or errors between 500 and 600. Stale serving is bounded by the directive duration and maximum TTL.
How can a team replace a CloudFront file before its TTL expires?
Invalidate the path, which can include a * wildcard, or publish a new versioned file name. AWS recommends versioned names for frequent updates to avoid invalidation charges and old browser or proxy copies.
Users still receive an old CloudFront asset after its invalidation has completed. Could their browser or corporate proxy be responsible?
Yes. Invalidation clears CloudFront edge copies, not browser or proxy copies. Publish a new versioned file name to select the new asset through those caches.
A site needs short browser caching but longer CloudFront caching for the same object. Which origin response directives should it use?
Use max-age for browsers and s-maxage for CloudFront. CloudFront still applies its minimum and maximum TTL bounds.
How does a CloudFront cache policy disable caching completely?
Set minimum, default and maximum TTLs all to 0.
Why does AWS recommend CloudFront OAC over legacy OAI for S3 origins?
OAC supports all S3 Regions, SSE-KMS objects, and PUT and DELETE requests. SSE-KMS also needs a KMS key policy allowing the distribution to use the key.
Can CloudFront OAC protect an S3 static website endpoint?
No. An S3 website endpoint is a custom origin and supports neither OAC nor OAI. Use a regular S3 bucket origin for OAC.
CloudFront OAC has a read grant in the S3 bucket policy, but the objects use SSE-KMS. Which additional resource policy must the team configure?
The KMS key policy. It must permit the CloudFront distribution to use the encryption key. The S3 read grant alone does not grant key access.
How should a team migrate a CloudFront S3 origin from OAI to OAC without losing origin access during deployment?
Allow both identities in the bucket policy first. Switch the distribution to OAC, wait until it is fully deployed, then remove the old OAI policy grant.
Which CloudFront OAC signing option guarantees HTTPS to its S3 bucket origin?
Sign requests, API value always. It signs every origin request. The no-override option preserves viewer Authorization when present and needs Authorization in the relevant cache policy.
An internet-facing ALB must accept traffic only from CloudFront. What restricts it at the network layer?
An ALB security group inbound rule that allows only the CloudFront managed prefix list (a custom origin header checked by the ALB adds a second control).
Which CloudFront origin group failures can send a request to its secondary origin?
Configured status codes from 400, 403, 404, 416, 429, 500, 502, 503 and 504. Connection failures require 503 selected; response timeouts require 504. Only GET, HEAD and cached OPTIONS can fail over.
Does CloudFront origin failover retry POST or PUT requests on the secondary origin?
No. Only GET, HEAD and OPTIONS are eligible, and OPTIONS must be a cached method.
With default CloudFront origin selection, do later cache misses keep using the secondary after a request fails over?
No. Each cache miss tries the primary before failover. A cache hit is served without contacting the origin group.
Which CloudFront origin settings can reduce the delay before origin failover?
Reduce connection timeout or connection attempts. Timeout is 1 to 10 seconds, default 10; attempts are 1 to 3, default 3. For custom origins, also adjust response timeout, 1 to 120 seconds, default 30. Default connection attempts can take up to 30 seconds.
An S3 static site behind CloudFront needs a second Region for read availability. How should the team prepare its origins?
Use S3 Cross-Region Replication for new and updated objects, and Batch Replication for existing objects when needed. Configure the two buckets as primary and secondary in an origin group and select it in the cache behavior.
A replicated S3 site uses a CloudFront origin group. During an outage, can the group retry uploads on the secondary?
No. The origin group fails over GET, HEAD and cached OPTIONS only. PUT and POST are not retried on the secondary.
A CloudFront distribution uses an origin group to fail over between S3 buckets in two Regions. What Route 53 record should send the site domain to it?
A simple alias record to the distribution. Failover between the buckets happens inside CloudFront through the origin group, so DNS failover routing has nothing to switch.
What does CloudFront Origin Shield add between regional edge caches and the origin?
Another caching layer that can serve hits and consolidate simultaneous misses for the same object into as few as one origin request. It adds charges.
A CloudFront origin is outside AWS, and most viewers are far away. How should the team choose the Origin Shield Region?
Choose the Region with the lowest latency to the origin. Origin Shield supports origins outside AWS and is configured per origin.
Several CDNs repeatedly request the same video objects from a capacity-limited origin. How can CloudFront Origin Shield reduce duplicate origin work?
Use the CloudFront distribution with Origin Shield as the origin for the other CDNs. Its shared cache and request consolidation reduce repeated fetches from the content origin.
Does enabling CloudFront Origin Shield guarantee better results for content that is rarely cacheable or requested?
No. Dynamic, poorly cacheable or infrequently requested content may be a poor fit, and Origin Shield adds charges.
When should CloudFront use signed URLs versus signed cookies for private content?
Use signed URLs for individual files or clients without cookies. Use signed cookies for multiple restricted files or unchanged URLs. AWS recommends trusted key groups for the public keys used to validate access.
A site uses CloudFront signed URLs, but its origin is publicly readable. Can viewers bypass the signed access restrictions?
Yes. Restrict origin access too: use OAC for S3, or require custom headers on a custom HTTP origin. Signed URLs alone do not protect direct origin URLs.
A subscriber site serves many restricted media files through CloudFront and must keep its current URLs. Which access mechanism should it use?
Signed cookies. The application authorizes the viewer and sends the three Set-Cookie headers that establish signed access.
A CloudFront download may begin only after a scheduled time and only from an approved IP range. Which signed access policy is required?
A custom policy. It can set an optional start time and client IP restriction; both canned and custom policies support expiry.
A CloudFront signed URL expires while a large file is downloading. Can the download finish, and can a disconnected client retry after expiry?
The download begun before expiry can finish. A retry or range request begun after expiry fails because CloudFront checks validity when each request begins.
A CloudFront distribution uses an alternate domain name. Where must its ACM viewer certificate be, and which names must it cover?
In us-east-1. The SAN must cover the alternate domain exactly or with a wildcard at the same level. An Elastic Load Balancing origin uses a separate regional certificate; provision that certificate in the Region where the load balancer uses it.
A CloudFront custom origin uses HTTPS but returns an invalid certificate. Which origin settings and certificate requirements should the team check?
Check the separate origin protocol policy and certificate. The policy is HTTP only, HTTPS only or Match viewer. For HTTPS, the certificate must be trusted and match the origin domain or forwarded Host domain. Invalid or mismatched certificates can cause 502.
How does a CloudFront cache behavior require viewers to use HTTPS and set their minimum TLS version?
Set viewer protocol policy to Redirect HTTP to HTTPS or HTTPS only. Choose a viewer security policy for the minimum TLS version and allowed ciphers. Configure origin HTTPS separately.
A form passes through several application components behind CloudFront, but only the final processor may read selected sensitive fields. What should the team use?
Field-level encryption. CloudFront encrypts up to 10 selected POST fields with the public key; only the component holding the private key can decrypt them. Configure HTTPS to viewers and origin and allow all supported HTTP methods.
CloudFront must serve HTTPS for a custom domain to clients that support SNI without dedicated IPs. How does it select the certificate?
The client sends the domain name in the TLS ClientHello SNI extension. CloudFront finds the matching distribution and returns its certificate. Dedicated IP HTTPS is an alternative for clients without SNI and adds a monthly charge.
A company's domain is hosted at a third-party DNS provider. Can it still serve www.example.com through Amazon CloudFront?
Yes. Point the name at the distribution domain name in that DNS provider; Route 53 alias records are optional.
How do CloudFront Functions and Lambda@Edge differ in events, runtime and access?
CloudFront Functions for HTTP delivery: JavaScript, viewer request and viewer response, submillisecond execution, no network or request body access. Lambda@Edge: Node.js or Python, all four viewer/origin events, up to 30 seconds, with network and request body access.
How must a Lambda@Edge function be deployed for a CloudFront cache behavior?
Create it in us-east-1, publish a numbered version, and associate that version with the behavior event. $LATEST and aliases are not accepted. AWS replicates the function globally.
A team must call an external API only when CloudFront forwards a request to the origin. Which edge function and event fit?
Lambda@Edge on origin request. It supports network access and skips cache hits. With an origin group, failover can invoke it twice for one viewer request.
A CloudFront application must call an identity service before serving protected content, including cache hits. Which edge option and request event should it use?
Lambda@Edge on viewer request. Lambda@Edge can make external credential checks, and the viewer request event runs before cache lookup. An origin request check is skipped on cache hits.
A team wants a lightweight CloudFront redirect and normalization of request values before cache lookup, without external calls. Which option fits?
A CloudFront Function on viewer request. CloudFront Functions supports lightweight redirects and cache key normalization at viewer events.
A Lambda@Edge origin-request function checks authorization. Does that check run for a valid CloudFront cache hit?
No. Origin-request functions run only when CloudFront forwards to the origin. Put checks that must cover cached responses before cache lookup, at viewer request.
When should a CloudFront distribution use geographic restrictions rather than AWS WAF geo match?
Use CloudFront geographic restrictions for a distribution-wide country allowlist or denylist. Use WAF geo match when geography must be combined with other conditions. CloudFront geo-blocked requests never reach WAF.
Can CloudFront speed up uploads to an S3 bucket, or only downloads?
Both. With all HTTP methods allowed, CloudFront forwards PUT and POST requests to the origin over the edge network. Only GET, HEAD and optionally OPTIONS responses are cached.
A CloudFront distribution uses mutual TLS and needs custom checks on client certificate properties during connection establishment. Which edge function type should it use?
A CloudFront Connection Function. It evaluates certificate and connection information during the TLS handshake and allows or denies the connection; it cannot modify HTTP requests or responses.
An internal ALB in private subnets must serve users through CloudFront without any public endpoint of its own. What does CloudFront offer?
A VPC origin. CloudFront reaches ALBs, NLBs and EC2 instances in private subnets over a private connection and becomes the only way in.
Serving S3 content through CloudFront instead of straight from S3: is the S3 to CloudFront transfer billed?
No. Transfer from AWS origins to CloudFront is free; you pay CloudFront delivery to viewers.