Jawahar
Jawahar

Reputation: 4885

How to create an AWS CDN invalidation which invalidates all URLs except few?

To invalidate cache for all URLs under /images, we can create invalidation like /images/* in AWS CloudFront. But if I want to clear cache for all the URLs, except /images, is there any way to do it?

I don't see an option for this in AWS documentation.

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#invalidation-specifying-objects-paths

Upvotes: 0

Views: 214

Answers (1)

Gonz
Gonz

Reputation: 1219

You might want to think of having to CloudFront distributions, one for your images which is most likely to not change as often, and another distribution for your website (html, css, js).

You can make your site point to two distributions, or depending on what server you are using (if using one) maybe create a re-write rule for the requests going to /images/* request the content from cdn/images/*.


Not a good solution

As Michael mentioned in the comment this solution it's going to be quite bad in terms of cost.

From the AWS docs:

Invalidation requests No additional charge for the first 1,000 paths requested for invalidation each month. Thereafter, $0.005 per path requested for invalidation.

You can't invalidate 'all' but a few. What you can do is list all the files in your S3 bucket but the images.

Try something like:

aws s3 ls | grep -v 'images'

And then create the invalidation based on the output of this.

Upvotes: 0

Related Questions