如何更新 Amazon CDN (CloudFront) 上的文件?
有没有办法更新存储在 Amazon CloudFront(亚马逊的 CDN 服务)上的文件? 似乎不需要对我们制作的文件进行任何更新(例如删除文件并使用与以前相同的文件名存储新文件)。 我是否必须显式触发更新过程以从边缘服务器中删除文件才能发布新文件内容?
感谢您的帮助
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
以下是我使用 CloudFront 控制面板执行此操作的方法。
例如:
一旦它说完成,你就可以开始了。
提示:
一旦您创建了一些失效,如果您回来并需要使相同的文件失效,请使用选择框,复制链接将变得可用,使其更快。
Here is how I do it using the CloudFront control panel.
For example:
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.
亚马逊添加了失效功能。 这是 API 参考。
API 参考中的示例请求:
Amazon added an Invalidation Feature. This is API Reference.
Sample Request from the API Reference:
设置 TTL=1 小时并替换
http://developer.amazonwebservices.com/connect /ann.jspa?annID=655
Set TTL=1 hour and replace
http://developer.amazonwebservices.com/connect/ann.jspa?annID=655
下载 Cloudberry Explorer 免费软件版本以对单个文件执行此操作:
http://blog.cloudberrylab.com/2010/08 /如何管理-cloudfront-object.html
Download Cloudberry Explorer freeware version to do this on single files:
http://blog.cloudberrylab.com/2010/08/how-to-manage-cloudfront-object.html
适用于 Mac 和 Windows 的 Cyberduck Windows 提供了用于对象失效的用户界面。 请参阅 http://trac.cyberduck.ch/wiki/help/en/howto /cloudfront。
Cyberduck for Mac & Windows provides a user interface for object invalidation. Refer to http://trac.cyberduck.ch/wiki/help/en/howto/cloudfront.
我似乎记得已经在 serverfault 上看到过这个,但答案是:
“Amazon CDN”我假设您的意思是“CloudFront”?
它已被缓存,因此如果您需要立即更新(而不是“新版本将在 24 小时内可见”),您必须选择一个新名称。 使用“logo.png--0”代替“logo.png”,然后使用“logo.png--1”更新它,并更改您的html以指向它。
没有办法“刷新”亚马逊云前端。
编辑:这以前不可能,但现在可以了。 请参阅此回复的评论。
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.
CloudFront 的用户界面在 [i] 按钮 > 下提供此功能。 “分发设置”选项卡“失效”:https://console.aws.amazon .com/cloudfront/home#distribution-settings
CloudFront's user interface offers this under the [i] button > "Distribution Settings", tab "Invalidations": https://console.aws.amazon.com/cloudfront/home#distribution-settings
在 ruby 中,即使在失效时使用雾宝石
,在所有亚马逊边缘服务器上处理和刷新失效仍然需要 5-10 分钟
In ruby, using the fog gem
even on invalidation, it still takes 5-10 minutes for the invalidation to process and refresh on all amazon edge servers
适用于 Win、Mac 和 Linux 的 CrossFTP 提供了用于 CloudFront 失效的用户界面,请查看以下内容以了解更多详细信息:
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
我将总结可能的解决方案。
情况一:一次性更新:使用Console UI。
您可以按照@CoalaWeb的答案手动浏览控制台的UI,并在CloudFront上启动“失效”,通常需要不到一分钟的时间完成。 只需单击一下即可。
此外,您可以在 UI 中手动更新它在 S3 中指向的路径。
案例 2:频繁更新,在 S3 中的同一路径上:使用 AWS CLI。
您可以使用 AWS CLI 通过命令行简单地运行上述内容。
命令为:
将
E1234567890
部分替换为您在控制台中可以看到的 DistributionId。 您还可以将其限制为某些文件,而不是所有文件的/*
。有关如何将其放入 Node/JavaScript 项目的
package.json
作为目标的示例,请参阅 此回答。 (不同的问题)注释:
CreateInvalidation
访问权限。 (以下例为例。)案例3:更新频繁,S3上的路径每次都会改变:使用手动脚本。
如果您在 S3 中存储不同版本的文件(即路径包含文件/工件的版本 ID),并且每次都需要在 CloudFront 中进行更改,则需要编写一个脚本来执行该操作。
遗憾的是,适用于 CloudFront 的 AWS CLI 不允许您使用一个命令轻松更新路径。 你需要有一个详细的脚本。 我写了一个,可以在这个答案中找到详细信息。 (不同的问题)
I am going to summarize possible solutions.
Case 1: One-time update: Use Console UI.
You can manually go through the console's UI as per @CoalaWeb's answer and initiate an "invalidation" on CloudFront that usually takes less than one minute to finish. It's a single click.
Additionally, you can manually update the path it points to in S3 there in the UI.
Case 2: Frequent update, on the Same path in S3: Use AWS CLI.
You can use AWS CLI to simply run the above thing via command line.
The command is:
Replace the
E1234567890
part with the DistributionId that you can see in the console. You can also limit this to certain files instead of/*
for everything.An example of how to put it in
package.json
for a Node/JavaScript project as a target can be found in this answer. (different question)Notes:
CreateInvalidation
access in IAM. (Example in the case below.)Case 3: Frequent update, the Path on S3 Changes every time: Use a Manual Script.
If you are storing different versions of your files in S3 (i.e. the path contains the version-id of the files/artifacts) and you need to change that in CloudFront every time, you need to write a script to perform that.
Unfortunately, AWS CLI for CloudFront doesn't allow you to easily update the path with one command. You need to have a detailed script. I wrote one, which is available with details in this answer. (different question)