Why isn't CloudFront following a cache behavior that I created?

2 minute read
0

I created a custom cache behavior for a specific URL path pattern on my distribution, but Amazon CloudFront isn't following the cache behavior.

Resolution

If your CloudFront distribution isn't following a cache behavior that you created, check the following configurations:

  • Review your distribution's behaviors. Confirm that there's a cache behavior for your requested path pattern. If the requested path pattern isn't correctly defined in a cache behavior, CloudFront uses the default cache behavior. For example, if a cache behavior has Path Pattern set to test/, then a request to example.com/test/file1.jpg follows the default cache behavior. The request won't follow the behavior specified for test/ because the path pattern is missing a wildcard at the end of the path (test/*).
  • Review the path pattern specified in the cache behavior. Confirm that the capitalization is correct. Path patterns specified in CloudFront are case-sensitive. References to buckets or objects in Amazon Simple Storage Service (Amazon S3) are also case-sensitive. If a path pattern has incorrect capitalization and your default cache behavior doesn't cache the requested content, users might receive a "404 Not Found" error.
  • If you recently changed the cache behavior, updated content appears after the existing content expires from the cache. If you want to serve the updated content before the existing content expires from the cache, then run an invalidation.

Note: CloudFront doesn't generate 404 responses. If a requested object isn't found in a CloudFront cache, then the request is sent to the origin. Then, the origin generates the 404 response.

Related information

Path pattern

How do I troubleshoot HTTP 404 (Not Found) errors in CloudFront?

AWS OFFICIAL
AWS OFFICIALUpdated 8 months ago