Overview
Invalidation in CloudFront allows you to remove cached content from the edge locations, ensuring that the latest version of your content is served. This is especially useful for scenarios like updating static assets (e.g., images, CSS, JS) or correcting errors in previously cached files.
Key Features
- Targeted Clearing: You can invalidate specific objects (e.g.,
/style.css) or use wildcard patterns (e.g., /assets/*).
- Immediate Effect: Once processed, the invalidated content is immediately fetched from the origin on the next request.
- Cost:
- Free Tier: Includes 1,000 paths per month.
- Beyond Free Tier: Each additional invalidation request costs $0.005 per path.
How Invalidation Works
- Request Submitted:
- CloudFront marks the invalidated objects as "stale" across all edge locations.
- Next Request:
- The edge location fetches the latest version of the object from the origin.
- Updated Cache:
- The edge location replaces the stale content with the updated content.
Practical Example
Scenario
Your website deployed a new main.css file, but CloudFront is still serving the older cached version. You need to invalidate this file.
Steps to Invalidate a File
- Go to the AWS Management Console > CloudFront.
- Navigate to your Distribution.
- Select the Invalidations tab > Create Invalidation.