How CloudFront Cache Invalidation Works and When to Use It
CloudFront invalidation explained: path and wildcard rules, 1,000 free paths a month, rate limits, tag invalidation and why versioned names are better.
A CloudFront invalidation tells every edge location to drop its cached copy of the paths you list, so the next request for those files goes back to your origin for the current version. You need it when content changed at the origin but the old copy has not yet expired from the cache. For files you update often, AWS recommends versioned file names instead, because they are cheaper and also defeat browser caches.
This guide explains how invalidation works, how to write paths that actually match, what it costs, the newer tag-based option, and when to skip invalidation entirely. All limits and behaviours below come from the CloudFront Developer Guide as checked in November 2026. For background on the service itself, read what Amazon CloudFront is and how it improves content delivery.
Key takeaways
- Invalidation removes objects from edge caches before they expire. The next viewer request fetches a fresh copy from the origin.
- The first 1,000 invalidation paths per month are free, counted across all distributions in one AWS account. A wildcard path such as
/images/*counts as one path however many files it matches. - The
*wildcard must be the last character of a path. Paths are case sensitive and can be up to 4,000 characters. - Invalidations cannot be cancelled once submitted. CloudFront forwards the request to all edge locations within a few seconds.
- Versioned file names (for example
app.3f9c2.js) are AWS's recommended approach for frequently updated files. - Tag invalidation lets you clear every object that carries a cache tag such as
#product:electronics, regardless of URL.
Why cached content goes stale
CloudFront keeps a copy of each object at the edge for a time to live (TTL). The TTL comes from your cache policy and from the Cache-Control or Expires headers your origin sends. If you do not use a cache policy, the default TTL is 24 hours. The managed CachingOptimized policy, which many S3-backed distributions use, has a minimum TTL of 1 second, a default of 86,400 seconds (24 hours) and a maximum of 31,536,000 seconds (365 days).
Until the TTL runs out, edge locations keep serving the copy they have. That is the whole point of a CDN: fewer trips to the origin and faster responses. The side effect is that when you upload a corrected price list, a new CSS file or a fixed JavaScript bundle under the same name, some viewers will keep getting the old version until it expires. Invalidation is how you shorten that wait to minutes when you cannot afford to leave it alone.
One more detail matters here. When a cached object expires, CloudFront does not necessarily download it again. It asks the origin whether the object changed, and if it has not, the origin answers 304 Not Modified. Invalidation is different: it removes the object outright, so the next request is a full cache miss.
How an invalidation works, step by step
- You submit an invalidation request with one or more paths, through the console, the CLI, an SDK or the
CreateInvalidationAPI. - CloudFront forwards the request to all edge locations within a few seconds, and each location starts processing it immediately. This is why AWS says you cannot cancel an invalidation after submitting it.
- Each edge location marks matching objects as invalid.
- The next viewer request for a matching path is treated as a miss. CloudFront fetches the object from the origin, caches it again with a fresh TTL, and serves it.
- The invalidation status changes from
InProgresstoCompletedonce all locations have processed it.
Nothing is pushed to the edge in advance. Invalidation only removes. If thousands of users request the invalidated files at once, all of those requests can reach your origin in a short window, so make sure the origin can handle a burst after a large invalidation, especially a /*.
Creating an invalidation
From the CLI, list the paths after --paths. Quote any path that contains *, otherwise your shell may expand it into local file names.
# one file
aws cloudfront create-invalidation \
--distribution-id EDFDVBD6EXAMPLE \
--paths "/css/site.css"
# several paths in one request
aws cloudfront create-invalidation \
--distribution-id EDFDVBD6EXAMPLE \
--paths "/index.html" "/about/index.html" "/images/*"
# check progress
aws cloudfront get-invalidation --distribution-id EDFDVBD6EXAMPLE --id I2J0I21PCUYOIK
aws cloudfront list-invalidations --distribution-id EDFDVBD6EXAMPLE
In the console, open the distribution, choose the Invalidations tab, then Create invalidation, and enter one path per line. The console lists the last 100 invalidations for the distribution; use the ListInvalidations API for older ones. You can also copy an earlier invalidation, edit the paths and run it again, which is handy for repeat jobs. Be careful when copying one that is still in progress: paths that appear in both will be invalidated twice and both count towards your monthly free paths.
Writing paths that match
Most "the invalidation didn't work" reports come down to a path that did not match what is in the cache. These are the rules from the documentation.
Paths are relative and case sensitive
The path is relative to the distribution. To invalidate https://d111111abcdef8.cloudfront.net/images/image2.jpg, you specify /images/image2.jpg. The console lets you omit the leading slash, but the API requires it. Paths are case sensitive, so /images/Image.jpg and /images/image.jpg are two different objects.
The wildcard goes last
The * matches zero or more characters and must be the final character in the path. An asterisk anywhere else is treated as a literal character. Useful patterns:
| Goal | Path |
|---|---|
| Every file in a directory and its subdirectories | /directory-path/* |
| The directory itself plus everything below it | /directory-path* |
| All extensions of one file name (logo.jpg, logo.png) | /directory-path/logo.* |
| All files starting with the same characters, such as HLS segments | /videos/movie1* |
| Every query string version of one file | /directory-path/file.ext* |
| Everything in the distribution | /* |
Query strings, cookies and headers
If your cache key includes query strings, each query string variant is a separate cached object, and you must include the query string in the path, for example /images/image.jpg?parameter1=a. To clear every variant, end the path with a wildcard: /images/image.jpg*.
Cookies and headers behave the other way round. If you cache based on cookies or header values, there may be several cached versions of one file, and an invalidation of that path removes all of them. You cannot selectively invalidate one cookie or header variant.
Directories, default root object and rewritten URLs
If your site is not consistent about trailing slashes, AWS suggests invalidating both forms, such as /images and /images/. The default root object is invalidated by its path like any other file. If a Lambda@Edge viewer request function rewrites URIs, for example from /index.html to /en/index.html, invalidate both the original and the rewritten URI.
Characters to watch
URL-encode non-ASCII and unsafe characters as defined in RFC 1738, and do not encode anything else, or the path will not match. The ~ character is not supported in invalidation paths at all, encoded or not. With signed URLs, invalidate using only the part of the URL before the question mark.
What invalidation costs
CloudFront gives every AWS account 1,000 free invalidation paths per month. That allowance is shared across all distributions in the account, so if you submit 600 paths on each of three distributions in a month, you pay for 800 paths. Above the free allowance you pay per path; check the CloudFront pricing page for the current rate in your plan.
The billing rule that matters most is about wildcards. A path with * counts as one path even if it invalidates thousands of files, and /* costs the same as a single file. But each path in a request is counted individually: bundling 50 paths into one request still counts as 50. Tag invalidations count against the same 1,000 free allowance, and a single tag counts as one path however many objects carry it.
This leads to a practical choice. If a deployment changes 300 files under /assets/, invalidating /assets/* is one path, while listing the files individually is 300. The wildcard is cheaper in money but sends more traffic to the origin, because unchanged files are also evicted. For most sites the wildcard is fine. For very large media libraries, think about the origin load first.
Rate limits
The CloudFront quotas page lists two limits on invalidations: 150 paths or tags per second, and 1 wildcard invalidation per second. There is no limit on how many files one wildcard or tag invalidation can process. If an automated pipeline fires many invalidation requests in a loop, build in retries with backoff rather than assuming every call succeeds the first time.
Versioned file names: usually the better answer
AWS's own recommendation, if you update files frequently, is to give each version a new name rather than invalidating. The documentation lists the reasons:
- Versioning controls exactly which file a request returns, even if a user has the old version cached in their browser or behind a corporate proxy. Invalidation only clears CloudFront's cache, not those other caches.
- Access logs contain the file names, so versioned names make it easier to see which version users received.
- You can serve different versions to different users.
- Rolling forward and back between versions is simpler.
- It is cheaper, because you pay nothing for invalidation. You still pay to transfer the new files to the edge.
Modern front-end build tools already do this by adding a content hash to bundle names, such as main.3f9c2a1b.js. The HTML page that references those bundles keeps a stable name like /index.html. A typical setup is:
- Hashed assets (JS, CSS, images): long cache lifetime, for example
Cache-Control: max-age=31536000, immutable. They never need invalidation, because a change produces a new name. - HTML entry points: a short lifetime such as
max-age=60, or invalidate just/index.htmlon each deploy.
With that split, a deployment needs at most a handful of invalidation paths, and users never load a new HTML page that points at an old bundle.
Tag-based invalidation
CloudFront also supports invalidation by cache tag. You opt in by adding a CacheTagConfig to the distribution that names the response header your origin uses for tags. The origin then returns a comma-separated list of tags with each object. For S3 origins, you can store the tags as object metadata; a metadata key of cache-tag is returned as the header x-amz-meta-cache-tag, which you name in the config.
# origin response header on a product page
# x-amz-meta-cache-tag: product:12345, category:tv, brand:example
# clear every cached object tagged brand:example
aws cloudfront create-invalidation \
--distribution-id EDFDVBD6EXAMPLE \
--paths "#brand:example"
# paths and tags can be mixed in one request
aws cloudfront create-invalidation \
--distribution-id EDFDVBD6EXAMPLE \
--paths "/index.html" "#category:tv"
Tags are case-insensitive, up to 256 characters each, and CloudFront stores up to 50 tags per object. Tag invalidation suits catalogues and content systems where one change affects many unrelated URLs, such as a brand update that touches hundreds of product pages spread across the site. Distributions without CacheTagConfig ignore tag headers.
Invalidation in a CI/CD pipeline
For a static site on S3 behind CloudFront, a deployment step often looks like this:
# 1. upload hashed assets with a long cache lifetime
aws s3 sync ./dist/assets s3://my-site-bucket/assets \
--cache-control "max-age=31536000,immutable"
# 2. upload HTML with a short lifetime
aws s3 sync ./dist s3://my-site-bucket \
--exclude "assets/*" --cache-control "max-age=60"
# 3. clear only the entry points
aws cloudfront create-invalidation \
--distribution-id "$CF_DISTRIBUTION_ID" \
--paths "/index.html" "/"
Upload assets before HTML, so that the new HTML never references a file that is not there yet. Keep the distribution ID in a pipeline variable rather than hard-coding it, and give the pipeline role permission for cloudfront:CreateInvalidation on that distribution only. The S3 side of this setup, including origin access control, is covered in how S3 works as a CloudFront origin and integrating S3 with CloudFront for secure file distribution.
Checking that it worked
After the invalidation shows Completed, request the file and look at the X-Cache response header. The first request after an invalidation should be a miss from CloudFront, and later ones hits. If you still see old content, check, in order: the path's case and leading slash, whether the cache key includes query strings you did not include, whether the browser is serving its own cached copy (try a private window or curl), and whether the origin itself still has the old file. Monitoring the effect on cache hit rate and origin load is covered in monitoring CloudFront edge locations and request metrics.
Common mistakes
- Invalidating
/*on every deploy when only a few HTML files changed. It works, but it evicts everything and loads the origin. - Forgetting the browser cache. Invalidation clears CloudFront, not the viewer's browser. Long browser lifetimes on unversioned files will still show old content.
- Putting the wildcard in the middle of a path. It is then a literal asterisk and matches nothing.
- Not quoting wildcards in the shell. Bash may expand
/*into local directories. - Using invalidation as a substitute for sensible TTLs. If you invalidate the same paths many times a day, shorten their TTL or version them.
Learn it hands-on
Cache behaviour, invalidation and S3 origins are everyday tasks for anyone running websites on AWS, and they are easiest to learn by breaking and fixing a real distribution. Our AWS Solutions Architect Associate training builds a CloudFront distribution end to end in lab, in the Kharadi, Pune classroom or live online. To round out the topic, read configuring CloudFront with SSL and custom domains.
Frequently asked questions
How long does a CloudFront invalidation take?
CloudFront forwards an invalidation to all edge locations within a few seconds, and each starts processing it immediately. Check the status with get-invalidation; it changes from InProgress to Completed when all locations have finished.
How much does CloudFront invalidation cost?
The first 1,000 invalidation paths per month are free across all distributions in an AWS account. Beyond that you pay per path at the rate on the CloudFront pricing page. A wildcard path or a tag counts as one path regardless of how many files it matches.
Can I cancel a CloudFront invalidation?
No. CloudFront sends the request to every edge location within seconds of submission, so it cannot be cancelled. Check your paths carefully before you submit.
Should I use invalidation or versioned file names?
AWS recommends versioned file names for files you update often. Versioning also bypasses browser and proxy caches, makes rollbacks easier, and costs nothing extra. Use invalidation for files that must keep a fixed name, such as index.html.
Why did my invalidation not remove the old file?
Common causes are a case mismatch in the path, a missing query string when the cache key includes query strings, a wildcard placed somewhere other than the end, or the viewer's browser serving its own cached copy.
What is a CloudFront tag invalidation?
It removes every cached object that carries a given cache tag, such as #product:electronics, regardless of URL. You enable it with a CacheTagConfig on the distribution that names the response header your origin uses for tags.
References
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0