A company distributes a multilingual web application globally using an Amazon CloudFront distribution. The origin server requires the viewer's language preference and device type to return the correct localized version of the page. Currently, the CloudFront distribution has a cache policy that forwards the raw `User-Agent` and `Accept-Language` headers to the origin. A SysOps administrator reports that the cache hit ratio is less than 5% because of the high variance in these headers. Which combination of actions should the administrator take to improve the cache hit ratio while ensuring the origin still receives the correct localization and device information?
- AMove the User-Agent and Accept-Language headers from the cache policy to an origin request policy, and keep them removed from the cache policy.
- BConfigure a Lambda@Edge function on the origin response event to overwrite the Cache-Control header to no-store, no-cache for all requests that include User-Agent or Accept-Language headers.
- Configure a CloudFront Function on the viewer request event to normalize the Accept-Language header to a set of supported language codes and write the value to a new X-Language header. Update the cache policy to cache on the X-Language header and the CloudFront device detection headers (such as CloudFront-Is-Mobile-Viewer), while removing the raw User-Agent and Accept-Language headers.Answer
- DReplace the CloudFront distribution's DNS record with a Route 53 CNAME record at the zone apex, and configure latency-based routing policies to bypass the cache for localized headers.
Answer
Configure a CloudFront Function on the viewer request event to normalize the Accept-Language header to a set of supported language codes and write the value to a new X-Language header. Update the cache policy to cache on the X-Language header and the CloudFront device detection headers (such as CloudFront-Is-Mobile-Viewer), while removing the raw User-Agent and Accept-Language headers.
The correct option is correct because using a CloudFront Function on the viewer request event allows the incoming Accept-Language header to be normalized to a limited set of language codes (such as 'en', 'es', or 'fr') and mapped to a custom header. Caching on this custom header and the built-in device detection headers (which are normalized to boolean values) instead of the raw headers dramatically reduces cache key cardinality and improves the cache hit ratio while preserving the origin's ability to localize content.
Step-by-Step Solution
Key Concept
CloudFront Cache Optimization using Header Normalization and Device Detection Headers