Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFront: How to clear cache

I am trying to remove the cache from my CloudFront, but I am going crazy with this.

What I did so far:

  1. Create bucket and set policy.
  2. Copy the endpoint from that (I test it on browser, and it's working).
  3. Create the CloudFront with the Min TTL: 1 sec.
  4. Downloaded S3 Browser and set HTTP Header to max-age=1

But still, if I update my S3 bucket, my Cloudfront is showing files that I already changed.

Can you guys point me on how to do it the right way? If there is a way to just clean cache when I want, even better, I just want to upload my files, see if CloudFront is showing the correct thing on Web, then I don't care anymore about the cache.

Thank you!

like image 733
user2852724 Avatar asked Jun 06 '15 16:06

user2852724


People also ask

How do I check my CloudFront cache?

To display CloudFront cache statisticsSign in to the AWS Management Console and open the CloudFront console at https://console.aws.amazon.com/cloudfront/v3/home . In the navigation pane, click Cache Statistics.

Where is CloudFront cached?

Regional edge caches are CloudFront locations that are deployed globally, close to your viewers. They're located between your origin server and the POPs—global edge locations that serve content directly to viewers.

Does CloudFront use cache?

CloudFront caches your objects based on the values in all of the specified headers. CloudFront also forwards the headers that it forwards by default, but it caches your objects based only on the headers that you specify.


1 Answers

You can use invalidation which is described in the documentation.

Recently this functionality was updated to allow to invalidate many objects at once. You can specify a path prefix and use : * to clear all cached objects.

enter image description here

However before deciding to use invalidations, please consider using versioned objects. There are many benefits to them described in the article referenced above.

like image 152
Alex Z Avatar answered Nov 24 '22 08:11

Alex Z