AWS CloudFront returns http 307 当源是 S3 桶时

AWS CloudFront returns http 307 when origin is S3 bucket

我已经用一些文件创建了 s3 存储桶。我创建了以该 S3 存储桶为源的 CloudFront 分配,并将状态更改为已部署。

当我为任何文件卷曲 CloudFront 时,我得到:

<Error><Code>TemporaryRedirect</Code><Message>Please re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests.</Message><Bucket>MY-BUCKET</Bucket><Endpoint>MY-BUCKET.s3-eu-west-1.amazonaws.com</Endpoint><RequestId>...</RequestId><HostId>...</HostId></Error>

当我为任何文件卷曲我的 S3 存储桶时,我会得到该文件的内容。

我做错了什么?如何强制cloudfront缓存文件,让客户端不需要直接从S3获取数据?

感谢 Matt Houser 对我的第一个评论 post!

CloudFront 似乎在分发尚未完全准备好时缓存了我对文件的第一个请求(但当时它处于部署状态,所以要小心!)。我请求使缓存中的所有文件失效,这需要几分钟时间,但在失效完成后,所有文件都使用 CloudFront url.

通过 http 200 进行了 curled

Michael-sqlbot 发表评论后问题变得清晰:

All buckets have at least two REST endpoint hostnames. In eu-west-1, they are example-bucket.s3-eu-west-1.amazonaws.com and example-bucket.s3.amazonaws.com. The first one will be immediately valid when the bucket is created. The second one -- sometimes referred to as the "global endpoint" -- which is the one CloudFront uses -- will not, unless the bucket is in us-east-1. Over a period of seconds to minutes, variable by location and other factors, it becomes globally accessible as well. Before that, the 307 redirect is returned. Hence, the bucket was not ready.

如果您遇到这种情况,请进一步说明,有几个选择:

  • 等待 up to 24h 更改完全传播。

  • 将存储桶位置更改为 us-east-1 区域。

  • 但最简单的方法可能是将您的 CloudFront 源域名从 <bucket>.s3.amazonaws.com 切换到 <bucket>.s3-<region>.amazonaws.com

转到您的分发设置 -> 起源和起源组并编辑当前起源

例如,在 us-west-2 区域中使用名为 Whosebug 的存储桶,它将变为

Whosebug.s3-us-west-2.amazonaws.com