静态站点在我的 S3 实例中工作,但在云端我收到错误 403 AccessDenied

static site works in my S3 instance but with cloudfront I'm getting an error 403 AccessDenied

我正在学习有关如何将静态站点部署到 s3 和云端的教程

https://miketabor.com/host-static-website-using-aws-s3/

我已经创建了我的 S3 存储桶,将其设置为 public,然后上传我的文件,网站如

http://www.yourdomain.com.s3-website-us-east-1.amazonaws.com

按预期工作,到目前为止一切顺利,现在我创建了云端实例,按照指南我的配置是这样的

Distribution ID
EMYC0...

ARN
arn:aws:cloudfront::22172726..981:distribution/EMYC0R..AP79B

Log Prefix
log_

Delivery Method
Web

Cookie Logging
Off

Distribution Status
Deployed

Comment
-
Price Class
Use All Edge Locations (Best Performance)

AWS WAF Web ACL
-

State
Enabled

Alternate Domain Names (CNAMEs)
dev.myurl.com

SSL Certificate
*.myurl.com (d89746a9-9d6d-45a9-b53c-ba24..36)

Domain Name
d1l63dvaobxx.cloudfront.net

Custom SSL Client Support
Clients that Support Server Name Indication (SNI) - (Recommended)

Security Policy
TLSv1.1_2016

Supported HTTP Versions
HTTP/2, HTTP/1.1, HTTP/1.0

IPv6
Enabled

Default Root Object
index.html (originally this was empty but I've changed this to index through not works neither)

Last Modified
2019-06-04 21:59 UTC-4

Log Bucket
www.dev.mybucketxx.com.s3.amazonaws.com

看完这篇文章

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DefaultRootObject.html#DefaultRootObjectHow

我认为问题出在默认的根对象上,它没有设置,所以我将其更改为 index.html(index.html 存在于我的 s3 存储桶的根中)

但我总是遇到这个错误

<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>06C89B31EE8CA0A5</RequestId><HostId>NGWaHdZx0EbbzLwVPOMx5DAY6lRgmPBCCInTQeab...IOSMStfnI6pwmu4QpDYU3R0EPNk=</HostId></Error>

我认为问题一定出在云端,因为我可以完美访问我的 S3,但我找不到问题所在

这是我的存储桶策略

{
    "Version": "2008-10-17",
    "Statement": [
        {
           "Sid": "AllowPublicRead",
           "Effect": "Allow",
           "Principal": {
               "AWS": "*"
           },
           "Action": "s3:GetObject",
           "Resource": "arn:aws:s3:::xxdomain.com/*"
       }
   ]
}

任何帮助将不胜感激,非常感谢你们!

这可能是因为您在定义源时从 auto-populated drop-down 菜单 select 编辑了 S3 存储桶。如果您只想通过 CloudFront 提供静态文件,如果您希望从 S3 提供静态网站,则 select 不应该这样做

创建源时,您必须粘贴到 URL 的 S3 网站,而不是 select 输入 auto-populated S3 存储桶。

您需要做的是:

1) 进入您的 S3 存储桶 > 属性 > 静态网站托管并复制网站 URL(注意:这与 S3 存储桶端点不同):

2) 进入您的 CloudFront 来源并粘贴此 URL

3) 这会将您的来源从 S3Origin(仅适用于静态文件)更改为 CustomOrigin

此更改传播后(大约 15 分钟),您应该能够通过您的 CloudFront 域名访问您的网站。