Mat*_*usz 7 amazon-s3 amazon-cloudfront serverless-framework serverless
我的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
Run Code Online (Sandbox Code Playgroud)
我想使用s3OriginConfig
和禁用通过 S3 存储桶的访问。我可以手动执行此操作。但我想得到如下图所示的效果:
Adi*_*tya 16
您可能已经解决了它,因为您很久以前就问过您的问题,但如果您不这样做,这可能会有所帮助。我也遇到了同样的问题,经过 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', /*]]
Run Code Online (Sandbox Code Playgroud)
参考资料:https : //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-cloudfront.html
归档时间: |
|
查看次数: |
2728 次 |
最近记录: |