A SysOps administrator is troubleshooting a low cache hit ratio on an Amazon CloudFront distribution that serves content from an Application Load Balancer (ALB). The administrator observes that the distribution is forwarding all query string parameters and headers to the ALB origin, which causes identical content requests with different user-agent headers and tracking query strings to be cached as separate objects. The origin application only requires the session_id query string parameter to function correctly. Which configuration change will improve the cache hit ratio while ensuring the application still receives the required parameter?
- ACreate a Canonical Name (CNAME) record in Amazon Route 53 at the zone apex that forwards the session_id query string parameter to the CloudFront distribution domain name.
- BRoute all traffic from the CloudFront distribution through a NAT Gateway inside the VPC to strip out any query parameters other than the session_id parameter.
- Configure a custom CloudFront Cache Policy that includes only the session_id query string parameter in the cache key, and associate this policy with the distribution's cache behavior.Answer
- DModify the Application Load Balancer target group health check settings to listen on a port that filters query parameters before traffic reaches the origin instances.
Answer
Configure a custom CloudFront Cache Policy that includes only the session_id query string parameter in the cache key, and associate this policy with the distribution's cache behavior.
The correct option is to configure a custom Cache Policy containing only the session_id query string parameter. Cache Policies determine the values (headers, cookies, and query strings) that make up the cache key. By limiting the cache key to only the session_id parameter, CloudFront ignores other variables like tracking parameters or User-Agent headers, thereby consolidating requests for identical objects into a single cache hit while still ensuring that session_id is forwarded to the origin.
Step-by-Step Solution
Key Concept
CloudFront Cache Policies manage cache key composition to optimize cache hit ratios by controlling which headers, cookies, and query strings are included in cache lookups.