我想要一个可以访问私有S3存储桶的CloudFront发行版。为此,我必须创建一个源访问标识。手动地,我可以使用亚马逊网络服务控制台,但我想通过一个CloudFormation脚本或使用无服务器(使用serverless.yml)来创建它。在这样做的同时,我能够将源访问标识的物理Id添加到我的CloudFront分发版中(使用一个脚本)。
相关文档:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-cloudfront.html
我试过这个:
myDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName:bucket.s3.amazonaws.com
Id: myS3Origin
S3OriginConfig: {
OriginAccessIdentity:origin-access-identity/cloudfront/ !Ref cloudfrontoriginaccessidentity
}
Enabled: 'true'
Comment: Some comment
DefaultCacheBehavior:
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: myS3Origin
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_200
ViewerCertificate:
CloudFrontDefaultCertificate: 'true'
cloudfrontoriginaccessidentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: "some comment"我必须创建一个源访问标识和一个具有该标识的CloudFront分发。我们可以在一个CloudFormation脚本中或使用无服务器(使用serverless.yml)来完成这两件事吗?
发布于 2019-02-18 15:57:13
您绝对可以在同一个serverless.yml中创建源访问标识和CloudFront分发。
我已经修改了您的方案,并将OriginAccessIdentity更改为使用Fn::Join。
myDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName:bucket.s3.amazonaws.com
Id: myS3Origin
S3OriginConfig:
OriginAccessIdentity:
Fn::Join:
- ''
-
- 'origin-access-identity/cloudfront/'
- Ref: cloudfrontoriginaccessidentity
Enabled: 'true'
Comment: Some comment
DefaultCacheBehavior:
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: myS3Origin
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_200
ViewerCertificate:
CloudFrontDefaultCertificate: 'true'
cloudfrontoriginaccessidentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: "some comment"无服务器示例存储库也有一个很好的例子:https://github.com/serverless/examples/blob/master/aws-node-single-page-app-via-cloudfront/serverless.yml
发布于 2019-02-15 23:14:10
可以,您可以在同一个CloudFormation模板中同时创建这两个文件。cloudfrontoriginaccessidentity是一个单独的资源,因此需要从myDistribution下移出。
myDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName:bucket.s3.amazonaws.com
Id: myS3Origin
S3OriginConfig: {
OriginAccessIdentity:origin-access-identity/cloudfront/ !Ref cloudfrontoriginaccessidentity
}
Enabled: 'true'
Comment: Some comment
DefaultCacheBehavior:
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
AllowedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: myS3Origin
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_200
ViewerCertificate:
CloudFrontDefaultCertificate: 'true'
cloudfrontoriginaccessidentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: "toyoguard-acces-identity"发布于 2019-09-27 03:15:17
不要忘记将s3策略和存储桶添加到您的dependsOn列表中
https://stackoverflow.com/questions/54711268
复制相似问题