Repository navigation
Expand file tree
/
Copy pathBasicStaticDistribution.yml
More file actions
156 lines (153 loc) · 4.88 KB
/
Copy pathBasicStaticDistribution.yml
File metadata and controls
156 lines (153 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
AWSTemplateFormatVersion: "2010-09-09"
Description: 'Hendric Jabs | Static Website Hosting'
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: 'Section 1: Website Configuration'
Parameters:
- DomainName
- IndexDocument
- ErrorDocument
- Custom404ErrorPage
- Label:
default: 'Section 2: Distribution Configuration'
Parameters:
- PriceClass
- UseDefaultTLSCertificate
- CertificateArn
- HostedZoneId
- Label:
default: 'Section 3: Logging Configuration'
Parameters:
- LoggingBucket
- LoggingPrefix
Parameters:
DomainName:
Description: Domain name used for bucket name and Route53 Entry.
Type: String
ConstraintDescription: must specify domain name.
IndexDocument:
Description: Index Document which is called if no other path is specified.
Type: String
Default: index.html
ErrorDocument:
Description: Document which is shown in case of an error.
Type: String
Default: error.html
Custom404ErrorPage:
Description: Document which is shown in case of a 404 error.
Type: String
Default: 404.html
PriceClass:
Description: Worldwide (PriceClass_All); World without South America and Australia (PriceClass_200); US, EU, Canada (PriceClass_100)
Type: String
AllowedValues:
- PriceClass_All
- PriceClass_200
- PriceClass_100
Default: PriceClass_100
UseDefaultTLSCertificate:
Description: Use the default certificate for HTTPS connections? For Production use DO NOT use the default certificate.
Type: String
AllowedValues:
- "true"
- "false"
Default: "false"
CertificateArn:
Description: If you don't want to use a default certificate, specify the ARN of a ACM certificate in US-East-1.
Type: String
HostedZoneId:
Description: The hosted zone
Type: AWS::Route53::HostedZone::Id
LoggingBucket:
Description: The Bucket where to store the CloudFront Logs.
Type: String
LoggingPrefix:
Description: The Prefix for log files.
Default: cloudfront
Type: String
Conditions:
UseDefaultCertificate: !Equals [ !Ref UseDefaultTLSCertificate, true ]
Resources:
OriginS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref DomainName
VersioningConfiguration:
Status: Enabled
WebsiteConfiguration:
ErrorDocument: !Ref ErrorDocument
IndexDocument: !Ref IndexDocument
OriginS3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref OriginS3Bucket
PolicyDocument:
Statement:
- Action:
- "s3:GetObject"
Effect: "Allow"
Resource: !Sub "arn:aws:s3:::${OriginS3Bucket}/*"
Principal:
CanonicalUser: !GetAtt CloudFrontOriginAccessIdentity.S3CanonicalUserId
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultRootObject: !Ref IndexDocument
Aliases:
- !Ref DomainName
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
CachedMethods:
- GET
- HEAD
Compress: false
DefaultTTL: 86400
TargetOriginId: !Ref DomainName
ViewerProtocolPolicy: https-only
ForwardedValues:
QueryString: false
Comment: !Sub "CloudFront Distribution for ${OriginS3Bucket}"
CustomErrorResponses:
- ErrorCachingMinTTL: 300
ErrorCode: 404
ResponseCode: 404
ResponsePagePath: !Ref Custom404ErrorPage
Enabled: true
IPV6Enabled: true
Logging:
Bucket: !Sub "${LoggingBucket}.s3.amazonaws.com"
Prefix: !Ref LoggingPrefix
Origins:
- DomainName: !GetAtt OriginS3Bucket.DomainName
Id: !Ref DomainName
S3OriginConfig:
OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}"
PriceClass: !Ref PriceClass
ViewerCertificate:
Fn::If:
- UseDefaultCertificate
- CloudFrontDefaultCertificate: true
- AcmCertificateArn: !Ref CertificateArn
SslSupportMethod: sni-only
CloudFrontOriginAccessIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: !Sub "Access Identity for ${OriginS3Bucket}"
Route53DNSRecordSet:
Type: "AWS::Route53::RecordSet"
Properties:
AliasTarget:
DNSName: !GetAtt CloudFrontDistribution.DomainName
# Fixed Hosted Zone for CloudFront
HostedZoneId: Z2FDTNDATAQYW2
Comment: "Alias Record to CloudFront Distribution."
HostedZoneId: !Ref HostedZoneId
Name: !Ref DomainName
Type: A