CloudFront + S3网站:“指定的密钥不存在”什么时候应该显示隐式索引文档 [英] CloudFront + S3 Website: "The specified key does not exist" when an implicit index document should be displayed

查看:154
本文介绍了CloudFront + S3网站:“指定的密钥不存在”什么时候应该显示隐式索引文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Amazon S3上部署了一个静态网站,目前可以在这里查看它:



S3抱怨文件不存在。现在,这就是奇怪的地方-我在域上使用CloudFront。因此,当您单击该文章链接时,它将请求发送到CloudFront,然后它尝试从S3存储桶取回文件。



但是,如果您访问相同的URL直接来自S3,例如: http://www.rdegges.com.s3-website-us-east-1.amazonaws.com/2015/building-a-heroku-addon-planning/ 该页面将可以正常加载。



似乎这里的翻译中有些东西迷路了。



任何人都对我可以提供的建议

解决方案

我会弯腰说指定的键不>技术上存在,因此错误消息在技术上是准确的,但并不能说明全部问题。



S3存储桶有两个¹端点, REST和网站。它们具有两个不同的功能集。网站端点提供了神奇的索引文档解析(例如index.html,在您提供的示例中,它实际上是应该返回给浏览器的内容),而REST端点却没有。



当您在用于网站托管的存储桶前面配置CloudFront时,通常不希望通过从下拉列表中选择存储桶名称来将源配置为 S3源清单相反,您希望将其配置为自定义来源,并使用S3控制台中提供的网站终结点主机名(例如 example-bucket.s3-website-us-east-1。 。),因为否则,CloudFront会假设您希望它对存储桶使用REST端点(它允许身份验证和私有内容,而网站端点则不允许)。


重要



不要从列表中选择存储桶的名称,例如example.com.s3.amazonaws.com。



http://docs.aws.amazon.com/gettingstarted/latest/ swh / getting-started-create-cfdist.html


由于该问题是最初回答,因此上面显示的消息现在稍后出现在一页上,并且h如改写,但要旨是相同的。 存储桶的名称似乎是指下拉菜单中显示的选项,而不是您想要的。


注意



请务必指定静态网站托管端点,而不是存储桶的名称。



http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-cloudfront-walkthrough.html


提示您将REST端点用于存储桶是因为如果您使用网站端点,则错误消息不会以XML格式显示-网站端点在以下位置返回错误消息HTML,而不是XML。



为CloudFront发行版创建新的来源,如所述,然后更改行为以将请求发送到新的来源,然后发送CloudFront缓存 / * 的无效请求,应该设置您。



另请参见:



http://docs.aws。 amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html#WebsiteRestEndpointDiff






¹两个端点。从技术上讲,有两个以上,因为所有存储桶都至少具有两个可能的REST端点主机名...,但是端点有两种 type 。存储桶还有一个可选的传输加速端点,该端点使用AWS边缘网络(为CloudFront供电的同一基础架构)进行更快/优化的传输,尤其是在距存储桶配置区域较远的地理位置,但不使用CloudFront缓存。如果您激活此端点,则它看起来像 https://example-bucket.s3-accelerate.amazonaws.com ,并且由于您正在使用,因此对大多数请求都收取额外的使用费更多的AWS网络和更少的公共Internet ...但是,这是端点的幕后部署的差异,而不是端点的行为。传输加速端点仍然是REST端点,因此,与其他REST端点一样,它不具有网站托管功能。 CloudFront不允许您将加速端点用于原始域名,因为这没有意义-如果允许这样的配置,则请求和响应将两次遍历AWS Edge Network,并增加延迟和成本,而没有提供任何好处。


I've just deployed a static website to Amazon S3, which can currently be viewed here: http://www.rdegges.com.s3-website-us-east-1.amazonaws.com/

If you click any of the article links, you'll notice the following error:

S3 is complaining the file doesn't exist. Now, here's what's weird about this -- I'm using CloudFront on my domain. So when you click that article link, it's sending the request to CloudFront which then tries to fetch the file back from the S3 bucket.

However, if you visit that same URL from S3 directly, eg: http://www.rdegges.com.s3-website-us-east-1.amazonaws.com/2015/building-a-heroku-addon-planning/ the page will load just fine.

It appears that something is getting lost in translation here.

Anyone got a suggestion of what I can do to fix my settings?

解决方案

I'll go out on a limb and say that the specified key doesn't technically exist, so the error message is technically accurate but doesn't tell the whole story. This should be an easy fix.

S3 buckets have two¹ endpoints, "REST" and "website." They have two different feature sets. The web site endpoint provides magical resolution of index documents (e.g. index.html, which appears to be what is actually supposed to be returned to the browser in the example you provided) while the REST endpoints don't.

When you configure CloudFront in front of a bucket used for web site hosting, you usually don't want to configure the origin as an "S3" origin by selecting the bucket name from the drop-down list; instead, you want to configure it as a "Custom" origin, and use the web site endpoint hostname as provided in the S3 console (e.g. example-bucket.s3-website-us-east-1...) because otherwise, CloudFront assumes you want it to use the REST endpoint for the bucket (which allows authentication and private content, which the web site endpoint doesn't).

Important

Do not select the name of your bucket from the list, for example, example.com.s3.amazonaws.com.

http://docs.aws.amazon.com/gettingstarted/latest/swh/getting-started-create-cfdist.html

The documentation was refactored since this question was originally answered, so the message shown above now appears one page later, and has been reworded, but the gist is the same. The "name of the bucket" seems to refer to the choices shown in the drop-down, which is not what you want.

Note

Be sure to specify the static website hosting endpoint, not the name of the bucket.

http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-cloudfront-walkthrough.html

The hint that you're using the REST endpoint for the bucket is because the error message wouldn't be in XML if you were using the web site endpoint -- the web site endpoint returns error messages in HTML, instead of XML.

Create a new origin for the CloudFront distribution, as described, then change the behavior to send requests to the new origin, then send a CloudFront cache invalidation request for /* and you should be set.

See also:

http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html#WebsiteRestEndpointDiff


¹ two endpoints. Technically, there are more than two, since all buckets have at least two possible REST endpoint hostnames... but there are two types of endpoints. Buckets also have an optional transfer acceleration endpoint that uses the AWS edge network (the same infrastructure that powers CloudFront) for faster/optimized transfers, particularly from geographic locations more distant from the region where the bucket is provisioned, but without using the CloudFront cache. This endpoint looks like https://example-bucket.s3-accelerate.amazonaws.com if you activate it, and carries an additional usage charge for most requests since you are using more of the AWS network and less of the public Internet... but, that is a difference in the behind-the-scenes deployment of the endpoint, not the behavior of the endpoint. The transfer acceleration endpoint is still a REST endpoint, so just like the other REST endpoints, it does not have the web site hosting features. CloudFront won't let you use an acceleration endpoint for an origin domain name, because that wouldn't make sense -- if such a configuration were allowed, requests and responses would loop through the AWS Edge Network twice and increase both latency and costs without providing any benefit.

这篇关于CloudFront + S3网站:“指定的密钥不存在”什么时候应该显示隐式索引文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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