Question #826
A company operates a global web application using Amazon CloudFront, but users report increasing latency. The operations team observes a declining cache hit ratio and identifies that the application generates varying HTTP headers (e.g., mixed-case "User-Agent" and "user-agent") for the same content, causing redundant cache entries. How should the solutions architect optimize caching efficiency?
Implement a Lambda@Edge function to normalize header keys to lowercase and remove unnecessary headers. Configure it using the CloudFront viewer request trigger.
Modify the CloudFront distribution to disable header-based caching entirely.
Deploy an Amazon API Gateway in front of the origin to standardize headers before reaching CloudFront.
Update the CloudFront cache policy to enable case-insensitive header matching.
Explanation
Answer A is correct because Lambda@Edge can normalize header keys to lowercase (e.g., converting 'User-Agent' to 'user-agent') and remove unnecessary headers at the viewer request stage. This ensures CloudFront uses a consistent cache key, resolving redundant entries caused by mixed-case headers.
Option B is incorrect because disabling header-based caching might break the application if headers are required for content targeting. Option C adds unnecessary complexity by introducing API Gateway, which isn't needed when Lambda@Edge can handle header normalization at the edge. Option D is invalid because CloudFront does not support case-insensitive header matching in cache policies—headers are case-sensitive by design.
Key Takeaway: Use Lambda@Edge to normalize headers in viewer requests to optimize CloudFront caching when headers vary in case or contain redundant values.
Answer
The correct answer is: A