Created
February 2, 2019 11:13
-
-
Save jonoirwinrsa/ceb2cba3d104720320f30e06b8c821f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Description: > | |
Script to create a SSL certificate, S3 bucket and Cloudfront distribution. | |
############################################################################### | |
Parameters: | |
############################################################################### | |
DomainName: | |
Type: String | |
Description: The domain name. | |
Default: webapp.example.com | |
PriceClass: | |
Type: String | |
Description: The CloudFront distribution price class | |
Default: 'PriceClass_All' | |
AllowedValues: | |
- 'PriceClass_100' | |
- 'PriceClass_200' | |
- 'PriceClass_All' | |
############################################################################### | |
Resources: | |
############################################################################### | |
Cert: | |
Type: AWS::CertificateManager::Certificate | |
Properties: | |
DomainName: !Ref DomainName | |
DomainValidationOptions: | |
- DomainName: !Ref DomainName | |
ValidationDomain: !Ref DomainName | |
ValidationMethod: DNS | |
CloudFrontDistribution: | |
Type: AWS::CloudFront::Distribution | |
Properties: | |
DistributionConfig: | |
Aliases: | |
- !Ref DomainName | |
DefaultCacheBehavior: | |
Compress: true | |
ForwardedValues: | |
QueryString: false | |
TargetOriginId: the-s3-bucket | |
ViewerProtocolPolicy: redirect-to-https | |
DefaultRootObject: index.html | |
CustomErrorResponses: | |
- ErrorCachingMinTTL: 300 | |
ErrorCode: 403 | |
ResponseCode: 200 | |
ResponsePagePath: /index.html | |
- ErrorCachingMinTTL: 300 | |
ErrorCode: 404 | |
ResponseCode: 200 | |
ResponsePagePath: /index.html | |
Enabled: true | |
HttpVersion: http2 | |
Origins: | |
- DomainName: !Join ['', [!Ref Bucket, '.s3.amazonaws.com']] | |
Id: the-s3-bucket | |
S3OriginConfig: | |
OriginAccessIdentity: | |
!Join ['', ['origin-access-identity/cloudfront/', !Ref CloudFrontOriginAccessIdentity]] | |
PriceClass: !Ref PriceClass | |
ViewerCertificate: | |
AcmCertificateArn: !Ref Cert | |
MinimumProtocolVersion: TLSv1 | |
SslSupportMethod: sni-only | |
Tags: | |
- Key: Domain | |
Value: !Ref DomainName | |
CloudFrontOriginAccessIdentity: | |
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity | |
Properties: | |
CloudFrontOriginAccessIdentityConfig: | |
Comment: !Sub 'CloudFront OAI for ${DomainName}' | |
Bucket: | |
Type: AWS::S3::Bucket | |
DeletionPolicy: Retain | |
Properties: | |
BucketEncryption: | |
ServerSideEncryptionConfiguration: | |
- ServerSideEncryptionByDefault: | |
SSEAlgorithm: AES256 | |
Tags: | |
- Key: Domain | |
Value: !Ref DomainName | |
BucketPolicy: | |
Type: AWS::S3::BucketPolicy | |
Properties: | |
Bucket: !Ref Bucket | |
PolicyDocument: | |
Statement: | |
- Action: | |
- s3:GetObject | |
Effect: Allow | |
Resource: !Join ['', ['arn:aws:s3:::', !Ref Bucket, '/*']] | |
Principal: | |
CanonicalUser: !GetAtt CloudFrontOriginAccessIdentity.S3CanonicalUserId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment