5

I would like to know if it's possible to clear CloudFront's cache,

The file concerned has changed on Amazon S3 but it's not being updated on CloudFront.

1
7

Might be useful to know you can also do this right from the AWS Console.

  • Distribution Settings > Invalidations > Create Invalidation

Then just type in the paths to invalidate in the same format displayed there.

See: Invalidating Objects (Web Distributions Only).

1
  • By far the easiest point-and-click method. Thanks! Mar 9 '14 at 20:30
6

I found the answer using Python:

import boto
cf = boto.connect_cloudfront('aws_access_key_id', 'aws_secret_access_key')
cf.create_invalidation_request("distribution_id", ["/path1","/path2"])

Documentation:

2
  • I was wondering how to get the distribution_id. Found it through the python shell, with help of boto.s3.amazonaws.com/ref/cloudfront.html
    – Rob W
    Oct 7 '12 at 10:18
  • Is a distribution id safe to hard-code in public source code or is it "sensitive" information (like the aws_access_key_id and aws_secret_access_key) that should be provided say, as an environment variable?
    – mdwhatcott
    May 12 '16 at 15:32
3

In case you use Google Chrome, you can use Cloudfront Purge Tool plugin.

Disclaimer: I'm the author.

Features include:

  • Do purge requests for all distributions tied to your credentials
  • View the status of the last 20 purge requests
  • Receive a Desktop Notification when the purge is done (can be turned off)

The source code is available on Github: https://github.com/sajal/Cloudfront-Purge-Tool

3
  • Do you have an example of what a purge request looks like using the plugin? I'm confused on how that works.
    – mheavers
    May 24 '12 at 16:10
  • What the complete url u wanna purge? if it is example.com/foo/bar.jpg you need to enter /foo/bar.jpg in the box
    – sajal
    May 25 '12 at 10:18
  • Works perfectly. It took about 10 minutes to purge cache for one image, but that's Amazon's fault. Thanks a lot for this!
    – sfarbota
    Nov 20 '13 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.