Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear Amazon CloudFront Cache completely?

Tags:

I made some changes to my origin server which now serves different data from same url.

I tried to clear my cache completely by doing the following invalidation in CF UI:

enter image description here

But this didn't work. How can I wipe off completely the Amazon CloudFront cache's in one go?

like image 359
codersofthedark Avatar asked Aug 13 '14 13:08

codersofthedark


People also ask

How do I empty my AWS cache?

You can use invalidations to clear AWS S3 cache. To create invalidations login to AWS Console and go to Distribution Settings > Invalidations > Create Invalidation. Once invalidation is created just type path of file or a wildcard to purge the cache.

How long does CloudFront cache last?

By default, CloudFront caches a response from Amazon S3 for 24 hours (Default TTL of 86,400 seconds). If your request lands at an edge location that served the Amazon S3 response within 24 hours, then CloudFront uses the cached response.

How do I refresh CloudFront content?

Right click your distribution. Select "Get Cloudfront invalidation list" Then select "Create" to create a new invalidation list. Select the files to invalidate, and click "Invalidate." Wait 5-15 minutes.


2 Answers

CloudFront does now support wildcard or full distribution invalidation. You will need do do one of the followng.

  • Invalidate each object that has changed
  • Invalidate /*
  • Version your objects so that they are considered new (Ie rename or querystring)

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#invalidating-objects-console

like image 179
imperalix Avatar answered Oct 02 '22 08:10

imperalix


You need to use /* instead of /.

Also, if you need to do this frequently, you can do it using the AWS CLI.

aws cloudfront create-invalidation --distribution-id=YOUR_DISTRIBUTION_ID --paths "/*" 

Edit: thanks to @speckledcarp, you need to use "/*" (with quotes) when using the CLI.

like image 26
Zanon Avatar answered Oct 02 '22 09:10

Zanon