如何更新 Amazon CDN (CloudFront) 上的文件?

发布于 2024-07-26 09:09:28 字数 158 浏览 4 评论 0原文

有没有办法更新存储在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

陪你搞怪i 2024-08-02 09:09:28

以下是我使用 CloudFront 控制面板执行此操作的方法。

  1. 从服务列表中选择 CloudFront。
  2. 确保选择左上角的Distributions
  3. 接下来,单击列表中关联分配的链接(在 id 下)。

在此处输入图像描述

  1. 选择无效选项卡。
  2. 单击创建失效按钮,然后输入要失效(更新)的文件的位置。

例如:

在此处输入图像描述

  1. 然后单击无效按钮现在您应该在状态下看到进行中

在此处输入图像描述

通常需要 10 到 15 分钟才能完成失效
请求,具体取决于您请求的大小。

一旦它说完成,你就可以开始了。

提示:
一旦您创建了一些失效,如果您回来并需要使相同的文件失效,请使用选择框,复制链接将变得可用,使其更快。

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).

enter image description here

  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:

enter image description here

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

enter image description here

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.

情独悲 2024-08-02 09:09:28

亚马逊添加了失效功能。 这是 API 参考

API 参考中的示例请求:

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>

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>
独自唱情﹋歌 2024-08-02 09:09:28

下载 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

梦忆晨望 2024-08-02 09:09:28

适用于 Mac 和 Windows 的 Cyber​​duck 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.

看轻我的陪伴 2024-08-02 09:09:28

我似乎记得已经在 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.

○愚か者の日 2024-08-02 09:09:28

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

我为君王 2024-08-02 09:09:28

在 ruby​​ 中,即使在失效时使用雾宝石

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

,在所有亚马逊边缘服务器上处理和刷新失效仍然需要 5-10 分钟

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

药祭#氼 2024-08-02 09:09:28

适用于 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

尬尬 2024-08-02 09:09:28

我将总结可能的解决方案。

情况一:一次性更新:使用Console UI。

您可以按照@CoalaWeb的答案手动浏览控制台的UI,并在CloudFront上启动“失效”,通常需要不到一分钟的时间完成。 只需单击一下即可。

此外,您可以在 UI 中手动更新它在 S3 中指向的路径。

案例 2:频繁更新,在 S3 中的同一路径上:使用 AWS CLI。

您可以使用 AWS CLI 通过命令行简单地运行上述内容。

命令为:

    aws cloudfront create-invalidation --distribution-id E1234567890 --paths "/*"

E1234567890 部分替换为您在控制台中可以看到的 DistributionId。 您还可以将其限制为某些文件,而不是所有文件的 /*

有关如何将其放入 Node/JavaScript 项目的 package.json 作为目标的示例,请参阅 此回答。 (不同的问题)

注释:

  • 我相信每月前 1000 个失效现在(2021 年 4 月)是免费的。
  • 执行 AWS CLI 失效的用户应在 IAM 中具有 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:

    aws cloudfront create-invalidation --distribution-id E1234567890 --paths "/*"

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:

  • I believe the first 1000 invalidations per month are free right now (April 2021).
  • The user that performs AWS CLI invalidation should have 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文