Overview
If you update the backend origin, CloudFront edge locations do not know about it. They only fetch the refreshed content once the TTL of the cache expires. If you want the new content served sooner, you can force a full or partial cache refresh, bypassing the TTL. This is a CloudFront invalidation.
You pass in file paths to invalidate:
| Pattern | Effect |
|---|---|
* |
Invalidate all files |
/index.html |
Invalidate a specific file |
/images/* |
Invalidate a path (all images) |
Example Flow
- A distribution has two edge locations. Each has its own cache with
index.htmland images from the S3 origin, with a TTL of one day. - An admin updates the S3 bucket: adds or changes images and changes
index.html. - The admin invalidates
/index.htmland/images/*. - CloudFront tells the edge locations to remove those files from their cache.
- On the next user request, the edge location finds the file is not in its cache, requests it from the origin, and gets the updated
index.html.
Origin content changed but users still see old content at the edge -> create a CloudFront invalidation instead of waiting for the TTL.
Cache invalidation flow
Questions & Answers
Q1: How do you make CloudFront serve updated origin content immediately?
Answer:
Run a cache invalidation for specific paths (e.g. /index.html, /images/*) or everything (*).
Q2: Without invalidation, when do edge locations get new content?
Answer:
Only after the TTL of the cached object expires.
Check yourself
Quiz
Flashcards
Click the card (or focus it), then use ← → to move and Space to flip.