Amazon S3 Cloudfront部署最佳实践 [英] Amazon S3 Cloudfront Deployment Best Practice

查看:231
本文介绍了Amazon S3 Cloudfront部署最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前的站点计划是将Amazon的Cloudfront服务用作资产文件(如CSS,JavaScript和图像以及任何其他静态文件)的CDN。

Our current plan for a site is to use Amazon's Cloudfront service as a CDN for asset files such as CSS, JavaScript, and Images, and any other static files.

我们目前在S3中有1个存储桶,其中包含所有这些静态文件。这些文件根据它们的位置分为不同的文件夹,脚本是JS文件,图像是图像,等等。yadda yadda yadda。

We currently have 1 bucket in S3 that contains all of these static files. The files are separated into different folders depending on what they are, "Scripts" are JS files, "Images" are Images, etc yadda yadda yadda.

从一开始就没有意识到,一旦您将S3中的存储桶部署到Cloudfront发行版,那么随后对该存储桶的所有后续更新都不会再部署到相同的发行版。因此,似乎每次您进行静态文件更新时都必须将存储桶重新部署到另一个Cloudfront实例。

So, what I didn't realize from the start was that once you deploy a Bucket from S3 to a Cloudfront Distribution, then every subsequent update to the bucket won't deploy again to that same Distribution. So, it looks as if you have to redeploy the bucket to another Cloudfront instance every time you have a static file update.

对于图像来说很好,因为我们可以轻松地使确保如果图像有更改,那么我们只是创建一个新图像。但这对于CSS和JS来说很难做到。

That's fine for images, because we can easily make sure that if there is a change to an image, then we just create a new image. But, that's difficult to do for CSS and JS.

因此,这使我想到了最佳实践问题:

So, that gets me to the Best Practice questions:


  1. 最佳做法是为每个生产部署创建另一个Cloudfront Distribution吗?

  2. 由于这些文件的性质,最好不要在Cloudfront中存储CSS和JS,这是最佳实践,因为它们很容易修改?似乎答案是否定的,因为这是CDN的目的。

  3. Cloudfront还有其他我不知道的方法吗?


推荐答案

您可以向CloudFront发出失效请求。

You can issue invalidation requests to CloudFront.

< a href = http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html rel = noreferrer> http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html

不过,我们使用自己的服务器作为自定义来源,而不是S3存储桶。我们有 .htaccess 别名 style _ *。css style.css ,然后在HTML中注入 style.css 的文件修改时间。由于CloudFront看到一个完全不同的URL,它将获取新版本。

Instead of an S3 bucket, though, we use our own server as a custom origin. We have .htaccess alias style_*.css to style.css, and we inject the file modification time for style.css in the HTML. As CloudFront sees a totally different URL, it'll fetch the new version.

(注意:某些CDN允许您通过查询字符串来执行此操作,但是CloudFront会忽略所有查询字符串数据进行缓存,因此 .htaccess 解决方案。)

(Note: Some CDNs let you do that via query string, but CloudFront ignores all query string data for caching, hence the .htaccess solution.)

编辑:CloudFront可以(可选)现在配置为使用查询字符串。

edit: CloudFront can be (optionally) configured to use query strings now.

这篇关于Amazon S3 Cloudfront部署最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆