Created
April 15, 2019 13:05
-
-
Save Sigmus/88f6e6a4e16efb7baa0e61c14d4cc93a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: "2010-09-09" | |
Parameters: | |
BucketName: | |
Type: String | |
Resources: | |
S3: | |
Type: "AWS::S3::Bucket" | |
Properties: | |
BucketName: !Ref BucketName | |
S3BucketPolicy: | |
Type: "AWS::S3::BucketPolicy" | |
Properties: | |
Bucket: !Ref BucketName | |
PolicyDocument: | |
Statement: | |
- Action: ["s3:GetObject"] | |
Effect: Allow | |
Principal: | |
AWS: | |
!Join [ | |
"", | |
[ | |
"arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ", | |
!Ref TheCloudFrontOriginAccessIdentity, | |
], | |
] | |
Resource: !Sub "arn:aws:s3:::${BucketName}/*" | |
TheCloudFrontDistribution: | |
Type: AWS::CloudFront::Distribution | |
Properties: | |
DistributionConfig: | |
#Aliases: | |
# - !Ref BucketName | |
DefaultCacheBehavior: | |
Compress: true | |
ForwardedValues: | |
QueryString: false | |
TargetOriginId: !Ref BucketName | |
ViewerProtocolPolicy: redirect-to-https | |
DefaultRootObject: index.html | |
CustomErrorResponses: | |
- ErrorCachingMinTTL: 300 | |
ErrorCode: 403 | |
ResponseCode: 404 | |
ResponsePagePath: /404.html | |
Enabled: true | |
HttpVersion: http2 | |
Origins: | |
- DomainName: !Join ["", [!Ref BucketName, ".s3.amazonaws.com"]] | |
Id: !Ref BucketName | |
S3OriginConfig: | |
OriginAccessIdentity: | |
!Join [ | |
"", | |
[ | |
"origin-access-identity/cloudfront/", | |
!Ref TheCloudFrontOriginAccessIdentity, | |
], | |
] | |
TheCloudFrontOriginAccessIdentity: | |
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity | |
Properties: | |
CloudFrontOriginAccessIdentityConfig: | |
Comment: !Sub "CloudFront OAI for ${BucketName}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aws cloudformation create-stack --stack-name test1 --template-body file://test1.yml --parameters ParameterKey=BucketName,ParameterValue=test1.foo.bar
aws cloudformation delete-stack --stack-name test1