Why isn't CloudFront following a cache behavior that I created?
Last updated: 2020-11-25
I created a custom cache behavior for a specific URL path pattern on my distribution, but Amazon CloudFront isn't following the cache behavior. Why?
If your CloudFront distribution isn't following a cache behavior that you created, check the following:
- Review your distribution's behaviors to be sure 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 to be sure 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 made changes to the cache behavior and you want to serve the updated content before the existing content expires from the cache, then consider running an invalidation.
Note: CloudFront doesn't generate 404 responses. If a requested object isn't found in a CloudFront cache, the request is sent to the origin and the origin generates the 404 response.