A SysOps administrator is troubleshooting a low cache hit ratio on an Amazon CloudFront distribution that serves a dynamic API. The application origin, hosted on EC2 instances behind an Application Load Balancer (ALB), requires the custom 'country-code' query string to return localized content, and the 'Authorization' header to authenticate each client request. Currently, the distribution's cache behavior is configured to forward all headers and query strings to the origin. Which configuration will maximize the cache hit ratio at the edge locations while ensuring the application still functions correctly?
- Create a custom Cache Policy that includes only the 'country-code' query string parameter in the cache key, and does not include the 'Authorization' header. Create a custom Origin Request Policy that forwards the 'Authorization' header to the origin, and associate both policies with the default cache behavior.Answer
- BCreate a CNAME record at the zone apex in Amazon Route 53 pointing to the CloudFront distribution domain name, and configure a custom Cache Policy that includes both the 'country-code' query string and the 'Authorization' header in the cache key.
- CConfigure Route 53 active-passive DNS failover routing to point to the ALB and a backup static origin, and configure the Cache Policy to include the 'Authorization' header while disabling query string caching.
- DCreate a custom Cache Policy that excludes the 'Authorization' header from the cache key, and update the stateless network access control list (NACL) of the ALB subnets to deny outbound ephemeral port ranges (1024-65535) to protect the authorization tokens.
Answer
Create a custom Cache Policy that includes only the 'country-code' query string parameter in the cache key, and does not include the 'Authorization' header. Create a custom Origin Request Policy that forwards the 'Authorization' header to the origin, and associate both policies with the default cache behavior.
The correct answer provides the optimal configuration by using a Cache Policy to define the cache key based only on the localized query string parameter, thereby keeping the cache hit ratio high. Simultaneously, the Origin Request Policy ensures that the authorization header is passed to the origin so that authentication checks succeed.
Step-by-Step Solution
Key Concept
CloudFront Cache Policies determine what is cached (cache key), while Origin Request Policies determine what is sent to the origin. Separating these concerns allows forwarding credentials without destroying cache efficiency.