我在serverless.yml文件中的这一行有问题。 我使用的是serverless-single-page-app-plugin。
# CustomOriginConfig:
# HTTPPort: 80
# HTTPSPort: 443
# OriginProtocolPolicy: https-only
## In case you want to restrict the bucket access use S3OriginConfig and remove CustomOriginConfig
S3OriginConfig:
OriginAccessIdentity: origin-access-identity/cloudfront/E127EXAMPLE51Z
我想使用s3OriginConfig并禁用通过s3存储桶的访问。我可以做这本手册。我想要获得如下图所示的效果
答案 0 :(得分:2)
您可能已经解决了,因为您很久以前就问过问题,但是如果您不这样做,这可能会有所帮助。我也面临同样的问题,在通过AWS文档进行了一些研究之后,我才知道如何使用所需的属性。关于您的问题,请考虑以下几点。
请根据您的问题找到以下代码段。
WebAppDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: 'passport-front.s3.amazonaws.com'
Id: 'WebApp'
S3OriginConfig:
OriginAccessIdentity: !Join ['', ['origin-access-identity/cloudfront/', !Ref CloudFrontOAI]]
CloudFrontOAI:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: 'access-identity-passport-front.s3.amazonaws.com'
WebAppBucket:
Type: AWS::S3::Bucket
DeletionPolicy: "Retain"
Properties:
AccessControl: PublicRead
BucketName: "passport-front"
WebAppBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref WebAppBucket
PolicyDocument:
Statement:
- Action: s3:GetObject
Effect: Allow
Principal:
CanonicalUser: !GetAtt CloudFrontOAI.S3CanonicalUserId
Resource: !Join ['', ['arn:aws:s3:::', !Ref 'WebAppBucket', /*]]
参考:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-cloudfront.html