How can I update files on Amazon's CDN (CloudFront)?

坚强是说给别人听的谎言 提交于 2019-12-30 02:02:47

问题


Is there any way to update files stored on Amazon CloudFront (Amazon's CDN service)? Seems like it won't take any update of a file we make (e.g. removing the file and storing the new one with the same file name as before). Do I have to explicitly trigger an update process to remove the files from the edge servers to get the new file contents published?

Thanks for your help


回答1:


Amazon added an Invalidation Feature. This is API Reference.

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>



回答2:


Here is how I do it using the CloudFront control panel.

  1. Select CloudFront from the list of services.
  2. Make sure Distributions from the top left is selected.
  3. Next click the link for the associated distribution from the list (under id).

  1. Select the Invalidations tab.
  2. Click the Create Invalidation button and enter the location of the files you want to be invalidated (updated).

For example:

  1. Then click the Invalidate button and you should now see InProgress under status.

It usually takes 10 to 15 minutes to complete your invalidation request, depending on the size of your request.

Once it says completed you are good to go.

Tip: Once you have created a few invalidations if you come back and need to invalidate the same files use the select box and the Copy link will become available making it even quicker.




回答3:


Set TTL=1 hour and replace

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




回答4:


Download Cloudberry Explorer freeware version to do this on single files: http://blog.cloudberrylab.com/2010/08/how-to-manage-cloudfront-object.html




回答5:


Cyberduck for Mac & Windows provides a user interface for object invalidation. Refer to http://trac.cyberduck.ch/wiki/help/en/howto/cloudfront.




回答6:


I seem to remember seeing this on serverfault already, but here's the answer:

By "Amazon CDN" I assume you mean "CloudFront"?

It's cached, so if you need it to be updated right now (as opposed to "new version will be visible in 24hours") you'll have to choose a new name. Instead of "logo.png", use "logo.png--0", and then update it using "logo.png--1", and change your html to point to that.

There is no way to "flush" amazon cloudfront.

Edit: This was not possible, it is now. See comments to this reply.




回答7:


CloudFront's user interface offers this under the [i] button > "Distribution Settings", tab "Invalidations": https://console.aws.amazon.com/cloudfront/home#distribution-settings




回答8:


In ruby, using the fog gem

AWS_ACCESS_KEY = ENV['AWS_ACCESS_KEY_ID']
AWS_SECRET_KEY = ENV['AWS_SECRET_ACCESS_KEY']
AWS_DISTRIBUTION_ID = ENV['AWS_DISTRIBUTION_ID']

conn = Fog::CDN.new(
    :provider => 'AWS',
    :aws_access_key_id => AWS_ACCESS_KEY,
    :aws_secret_access_key => AWS_SECRET_KEY
)

images = ['/path/to/image1.jpg', '/path/to/another/image2.jpg']

conn.post_invalidation AWS_DISTRIBUTION_ID, images

even on invalidation, it still takes 5-10 minutes for the invalidation to process and refresh on all amazon edge servers




回答9:


CrossFTP for Win, Mac, and Linux provides a user interface for CloudFront invalidation, check this for more details: http://crossftp.blogspot.com/2013/07/cloudfront-invalidation-with-crossftp.html



来源:https://stackoverflow.com/questions/1086240/how-can-i-update-files-on-amazons-cdn-cloudfront

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!