A Guide to AWS CloudFront Invalidations
Source: Dev.to

Static frontend websites require consistent updates as they grow. Typically, static web content is served by files uploaded to an Amazon S3 bucket and accessed via CloudFront. A common issue is that users may still see an older version of a page after new content has been uploaded. This happens because CloudFront caches the content.
To fix this, you need to perform a CloudFront invalidation. This guide walks you through the process step‑by‑step, ensuring your audience always sees the most recent version of your content.
What is S3 Object Invalidation?
When you use Amazon S3 to store files and Amazon CloudFront to deliver them, CloudFront caches copies of your files in edge locations around the world. This speeds up delivery because the data is physically closer to users.
CloudFront keeps those cached copies until they expire (often 24 hours or more). If you upload a new version of a file to S3, CloudFront won’t know it changed. An invalidation tells CloudFront to delete its cached copies and fetch the new version from S3 immediately.
Step‑by‑Step: How to Invalidate a File
-
Access the CloudFront Console
Sign in to the AWS Management Console, type “CloudFront” in the search bar, and select the service. -
Select Your Distribution
Locate the distribution that connects your S3 bucket to the web and click its Distribution ID. -
Create the Invalidation
- Click the Invalidations tab.
- Press the orange Create invalidation button.
-
Define the Object Path
In the “Object paths” box, specify the path of the file you want to clear.
Important: Do not paste the full URL—only the path after the domain name.Example: For a file at
https://example.com/restaurant/dinner.pdf, enter:/restaurant/dinner.pdfClick Create invalidation at the bottom of the page.
Key Points to Remember
- Leading Slash: Always start the path with a forward slash (
/). - Wildcards: To clear an entire folder, use an asterisk, e.g.,
/restaurant/*. - Timing: Invalidations usually take 1–3 minutes to process globally. When the status changes from “In Progress” to “Completed,” the new file is live.
Additional Resources
For more technical details on web caching and advanced invalidation patterns, refer to the official AWS documentation: