CloudFront Continues to Serve Old Content After Invalidation and S3 Update

1

I am encountering an issue with CloudFront where it continues to serve old content even after I've updated my S3 bucket with new files for my static website and performed an invalidation. Here are the steps I've taken:

Deployed a static website to an S3 bucket, with Route 53 for DNS and CloudFront for content delivery. Updated the website by deleting the old content from the S3 bucket and uploading new files. Created an invalidation in CloudFront for all files using the /* path pattern. Confirmed the invalidation has completed and is listed as 'Completed' in the AWS Management Console and via the AWS CLI. Despite these steps, when I access my website via the CloudFront URL, it still serves the old version of the site.

I have also reviewed the CloudFront Developer Guide section on invalidation (AWS Documentation on Invalidation: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html) and have followed the recommended steps.

Here are the additional steps I've tried:

I tried to add the invalidation through both the AWS Management Console and the AWS CLI. Cleared browser cache and tried accessing the site from different browsers and incognito mode to rule out local caching issues. Could there be a propagation delay that I'm not aware of, or is there a possible misconfiguration?

Thank you in advance for your help!

1 Answer
0

There are 4 ways to control how long CloudFront caches S3 content: 1. Set maximum TTL, 2. Implement content versioning, 3. Specify cache-control headers, 4. Use CloudFront invalidation requests.

By default, CloudFront caches files in edge locations for 24 hours. Best practice is to include a unique version identifier either in your file names or in your directory names. It can be a timestamp, a sequential number, or any other way that allows you to distinguish between two versions of the same file. For example, instead of banner.jpg, call it banner_20170401_v1.jpg. When you update the image, name the new version banner_20170612_v1.jpg and update all files that need to link to the new image. Another option is to manage CloudFront expiration behavior by specifying Cache-Control headers for your website content. If you keep the Minimum TTL at the default 0 seconds, then CloudFront honors any Cache-Control: max-age HTTP header that is individually set for your content. If an image is configured with a Cache- Control: max-age=60header, then CloudFront expires it at the 60 second mark. This gives you more precise control over content expiration for individual files.

See: Adding, removing, or replacing content that CloudFront distributes

Invalidation requests aren’t immediate. It takes several minutes from the time you submit one to the time that CloudFront actually expires the content. In addition, CloudFront lets you specify which content should be invalidated: You can choose to invalidate your entire Amazon S3 bucket, individual files, or just those matching a wildcard pattern.

Best practice is to understand and use the four approaches together. If possible, implement content versioning. It gives you the ability to immediately review changes and gives you the most precise control over the CloudFront and Amazon S3 experience. Set the Minimum TTL to be 0 seconds and the Maximum TTL to be a relatively low value. Also, use ode>Cache-Control headers for individual pieces of content. If your website is infrequently updated, then set a large value for Cache-Control:max-age=<seconds> and then issue CloudFront invalidation requests every time your site is updated. If the website is updated more frequently, use a relatively small value for Cache-Control:max-age=<seconds> and then issue CloudFront invalidation requests only if the Cache-Control:max-age=<seconds> settings exceeds several minutes.

See: Controlling how long Amazon S3 content is cached by Amazon CloudFront

Great article on real-world examples of how to implement “tiered TTL” expiration using versioning together with the right cache strategy using HTTP headers: Host Single Page Applications (SPA) with Tiered TTLs on CloudFront and S3

Did this help you resolve the issue?

AWS
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions