1
+ {
2
+ "AWSTemplateFormatVersion" : " 2010-09-09" ,
3
+ "Description" : " Hosting resource stack creation using Amplify CLI" ,
4
+ "Parameters" : {
5
+ "env" : {
6
+ "Type" : " String"
7
+ },
8
+ "bucketName" : {
9
+ "Type" : " String"
10
+ }
11
+ },
12
+ "Conditions" : {
13
+ "ShouldNotCreateEnvResources" : {
14
+ "Fn::Equals" : [
15
+ {
16
+ "Ref" : " env"
17
+ },
18
+ " NONE"
19
+ ]
20
+ }
21
+ },
22
+ "Resources" : {
23
+ "S3Bucket" : {
24
+ "Type" : " AWS::S3::Bucket" ,
25
+ "DeletionPolicy" : " Retain" ,
26
+ "Properties" : {
27
+ "BucketName" : {
28
+ "Fn::If" : [
29
+ " ShouldNotCreateEnvResources" ,
30
+ {
31
+ "Ref" : " bucketName"
32
+ },
33
+ {
34
+ "Fn::Join" : [
35
+ " " ,
36
+ [
37
+ {
38
+ "Ref" : " bucketName"
39
+ },
40
+ " -" ,
41
+ {
42
+ "Ref" : " env"
43
+ }
44
+ ]
45
+ ]
46
+ }
47
+ ]
48
+ },
49
+ "WebsiteConfiguration" : {
50
+ "IndexDocument" : " index.html" ,
51
+ "ErrorDocument" : " index.html"
52
+ },
53
+ "CorsConfiguration" : {
54
+ "CorsRules" : [
55
+ {
56
+ "AllowedHeaders" : [
57
+ " Authorization" ,
58
+ " Content-Length"
59
+ ],
60
+ "AllowedMethods" : [
61
+ " GET"
62
+ ],
63
+ "AllowedOrigins" : [
64
+ " *"
65
+ ],
66
+ "MaxAge" : 3000
67
+ }
68
+ ]
69
+ }
70
+ }
71
+ },
72
+ "PrivateBucketPolicy" : {
73
+ "Type" : " AWS::S3::BucketPolicy" ,
74
+ "DependsOn" : " OriginAccessIdentity" ,
75
+ "Properties" : {
76
+ "PolicyDocument" : {
77
+ "Id" : " MyPolicy" ,
78
+ "Version" : " 2012-10-17" ,
79
+ "Statement" : [
80
+ {
81
+ "Sid" : " APIReadForGetBucketObjects" ,
82
+ "Effect" : " Allow" ,
83
+ "Principal" : {
84
+ "CanonicalUser" : {
85
+ "Fn::GetAtt" : [
86
+ " OriginAccessIdentity" ,
87
+ " S3CanonicalUserId"
88
+ ]
89
+ }
90
+ },
91
+ "Action" : " s3:GetObject" ,
92
+ "Resource" : {
93
+ "Fn::Join" : [
94
+ " " ,
95
+ [
96
+ " arn:aws:s3:::" ,
97
+ {
98
+ "Ref" : " S3Bucket"
99
+ },
100
+ " /*"
101
+ ]
102
+ ]
103
+ }
104
+ }
105
+ ]
106
+ },
107
+ "Bucket" : {
108
+ "Ref" : " S3Bucket"
109
+ }
110
+ }
111
+ },
112
+ "OriginAccessIdentity" : {
113
+ "Type" : " AWS::CloudFront::CloudFrontOriginAccessIdentity" ,
114
+ "Properties" : {
115
+ "CloudFrontOriginAccessIdentityConfig" : {
116
+ "Comment" : " CloudFrontOriginAccessIdentityConfig"
117
+ }
118
+ }
119
+ },
120
+ "CloudFrontDistribution" : {
121
+ "Type" : " AWS::CloudFront::Distribution" ,
122
+ "DependsOn" : [
123
+ " S3Bucket" ,
124
+ " OriginAccessIdentity"
125
+ ],
126
+ "Properties" : {
127
+ "DistributionConfig" : {
128
+ "HttpVersion" : " http2" ,
129
+ "Origins" : [
130
+ {
131
+ "DomainName" : {
132
+ "Fn::GetAtt" : [
133
+ " S3Bucket" ,
134
+ " DomainName"
135
+ ]
136
+ },
137
+ "Id" : " hostingS3Bucket" ,
138
+ "S3OriginConfig" : {
139
+ "OriginAccessIdentity" : {
140
+ "Fn::Join" : [
141
+ " " ,
142
+ [
143
+ " origin-access-identity/cloudfront/" ,
144
+ {
145
+ "Ref" : " OriginAccessIdentity"
146
+ }
147
+ ]
148
+ ]
149
+ }
150
+ }
151
+ }
152
+ ],
153
+ "Enabled" : " true" ,
154
+ "DefaultCacheBehavior" : {
155
+ "AllowedMethods" : [
156
+ " DELETE" ,
157
+ " GET" ,
158
+ " HEAD" ,
159
+ " OPTIONS" ,
160
+ " PATCH" ,
161
+ " POST" ,
162
+ " PUT"
163
+ ],
164
+ "TargetOriginId" : " hostingS3Bucket" ,
165
+ "ForwardedValues" : {
166
+ "QueryString" : " false"
167
+ },
168
+ "ViewerProtocolPolicy" : " redirect-to-https" ,
169
+ "DefaultTTL" : 86400 ,
170
+ "MaxTTL" : 31536000 ,
171
+ "MinTTL" : 60 ,
172
+ "Compress" : true
173
+ },
174
+ "DefaultRootObject" : " index.html" ,
175
+ "CustomErrorResponses" : [
176
+ {
177
+ "ErrorCachingMinTTL" : 300 ,
178
+ "ErrorCode" : 400 ,
179
+ "ResponseCode" : 200 ,
180
+ "ResponsePagePath" : " /"
181
+ },
182
+ {
183
+ "ErrorCachingMinTTL" : 300 ,
184
+ "ErrorCode" : 403 ,
185
+ "ResponseCode" : 200 ,
186
+ "ResponsePagePath" : " /"
187
+ },
188
+ {
189
+ "ErrorCachingMinTTL" : 300 ,
190
+ "ErrorCode" : 404 ,
191
+ "ResponseCode" : 200 ,
192
+ "ResponsePagePath" : " /"
193
+ }
194
+ ]
195
+ }
196
+ }
197
+ }
198
+ },
199
+ "Outputs" : {
200
+ "Region" : {
201
+ "Value" : {
202
+ "Ref" : " AWS::Region"
203
+ }
204
+ },
205
+ "HostingBucketName" : {
206
+ "Description" : " Hosting bucket name" ,
207
+ "Value" : {
208
+ "Ref" : " S3Bucket"
209
+ }
210
+ },
211
+ "WebsiteURL" : {
212
+ "Value" : {
213
+ "Fn::GetAtt" : [
214
+ " S3Bucket" ,
215
+ " WebsiteURL"
216
+ ]
217
+ },
218
+ "Description" : " URL for website hosted on S3"
219
+ },
220
+ "S3BucketSecureURL" : {
221
+ "Value" : {
222
+ "Fn::Join" : [
223
+ " " ,
224
+ [
225
+ " https://" ,
226
+ {
227
+ "Fn::GetAtt" : [
228
+ " S3Bucket" ,
229
+ " DomainName"
230
+ ]
231
+ }
232
+ ]
233
+ ]
234
+ },
235
+ "Description" : " Name of S3 bucket to hold website content"
236
+ },
237
+ "CloudFrontDistributionID" : {
238
+ "Value" : {
239
+ "Ref" : " CloudFrontDistribution"
240
+ }
241
+ },
242
+ "CloudFrontDomainName" : {
243
+ "Value" : {
244
+ "Fn::GetAtt" : [
245
+ " CloudFrontDistribution" ,
246
+ " DomainName"
247
+ ]
248
+ }
249
+ },
250
+ "CloudFrontSecureURL" : {
251
+ "Value" : {
252
+ "Fn::Join" : [
253
+ " " ,
254
+ [
255
+ " https://" ,
256
+ {
257
+ "Fn::GetAtt" : [
258
+ " CloudFrontDistribution" ,
259
+ " DomainName"
260
+ ]
261
+ }
262
+ ]
263
+ ]
264
+ }
265
+ },
266
+ "CloudFrontOriginAccessIdentity" : {
267
+ "Value" : {
268
+ "Ref" : " OriginAccessIdentity"
269
+ }
270
+ }
271
+ }
272
+ }
0 commit comments