gpt4 book ai didi

amazon-web-services - Cloudfront 访问被拒绝

转载 作者:行者123 更新时间:2023-12-03 07:41:55 24 4
gpt4 key购买 nike

我正在尝试使用 Cloudformation 创建具有 S3 源的 Cloudfront。我想限制 S3 对象只能通过 Cloudfront 访问。但是,我使用 S3 直接 url 和 Cloudfront url 都被拒绝访问。

AWSTemplateFormatVersion: "2010-09-09"
Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
CloudFrontOriginIdentity:
Type: 'AWS::CloudFront::CloudFrontOriginAccessIdentity'
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: 'origin identity'
BucketPolicy:
Type: 'AWS::S3::BucketPolicy'
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Statement:
- Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${CloudFrontOriginIdentity}'
Action: 's3:GetObject'
Resource: !Sub 'arn:aws:s3:::${S3Bucket}/*'
CloudFrontDistribution:
Type: 'AWS::CloudFront::Distribution'
Properties:
DistributionConfig:
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
CachedMethods:
- GET
- HEAD
- OPTIONS
Compress: true
DefaultTTL: 3600
ForwardedValues:
Cookies:
Forward: none
QueryString: false
MaxTTL: 86400
MinTTL: 60
TargetOriginId: s3origin
ViewerProtocolPolicy: 'redirect-to-https'
DefaultRootObject: 'index.html'
Enabled: true
HttpVersion: http2
Origins:
- DomainName: !GetAtt 'S3Bucket.DomainName'
Id: s3origin
S3OriginConfig:
OriginAccessIdentity: !Sub 'origin-access-identity/cloudfront/${CloudFrontOriginIdentity}'

在S3中,我得到了index.html,里面只有Hello。

已创建存储桶策略

{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity xxxxxxxxxxxx"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mystack-s3bucket-xxxxxxxxxxx/*"
}
]
}

最佳答案

我在我的沙盒帐户中部署了您的模板。它按预期工作。存储桶、策略、CF 发行版都很好,我的示例网站也可以运行。

只需确保您使用 CF 域名从互联网访问您的静态网站,而不是存储桶 url,因为我见过有人错误地将存储桶 url 与 CF 一起使用。其形式为

ddd7asdf234sa.cloudfront.net

关于amazon-web-services - Cloudfront 访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64972503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com