views:

1214

answers:

4

I'm using Amazon's CloudFront to serve static files of my web apps.

Is there no way to tell a cloudfront distribution that it needs to refresh it's file or point out a single file that should be refreshed?

Amazon recommend that you version your files like logo_1.gif, logo_2.gif and so on as a workaround for this problem but that seems like a pretty stupid solution. Is there absolutely no other way?

+1  A: 

I think i found the answer here: http://stackoverflow.com/questions/1086240/updateing-files-on-amazons-cdn

With other words: It's impossible.

That makes me wonder how are you guys using cloudfront? When I deploy my apps i want't to upload all static files to s3. With s3 that works fine but beacuse of this 24h delay on cloudfront i can't use cloudfront.

Martin
maybe you should put a timestamp or a revision number in the filename
lhahne
A: 

The various caches can take up to 24 hours to clear, and cloudfront does not honor query strings, so there isn't really anyway to force the cache to expire prematurely inside a single distribution.

A couple helpful notes:

  1. Consider publishing a new cloudfront distribution every time you update your website. There is still a significant delay while you wait for the new dns record to replicate, but it will be considerably less than 24 hours for most of your users. I try to publish all my static files to a brand new distribution a couple hours before deploying my website changes. Then, the files are ready to go by the time I flip the switch to the new URL root.

  2. Any user generated images, or other files that are likely to change between website revisions should be served directly off of s3 rather than cloudfront (assuming you have your website setup to push images automatically to s3). There is simply no way to reliably server transactional files from cloudfront.

Good Luck!

Ben
+1  A: 

Set TTL=1 hour and replace

http://developer.amazonwebservices.com/connect/ann.jspa?annID=655

Hml
+3  A: 

Good news. Amazon finally added an Invalidation Feature. See the API Reference.

This is a sample request from the API Reference:

POST /2010-08-01/distribution/[distribution ID]/invalidation HTTP/1.0
Host: cloudfront.amazonaws.com
Authorization: [AWS authentication string]
Content-Type: text/xml

<InvalidationBatch>
   <Path>/image1.jpg</Path>
   <Path>/image2.jpg</Path>
   <Path>/videos/movie.flv</Path>
   <CallerReference>my-batch</CallerReference>
</InvalidationBatch>
James Lawruk
Sweeeeeeeeeeeeeet!
Martin