-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
320 lines (306 loc) · 10.3 KB
/
Copy pathtemplate.yaml
File metadata and controls
320 lines (306 loc) · 10.3 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
Description: b10cks Nuxt.js Website with Lambda, S3 and CloudFront
Parameters:
DomainName:
Type: String
Description: "The domain name of website"
Default: "b10cks.com"
AddWildcardSubdomains:
Type: String
Description: "Add wildcard subdomains to website"
Default: True
AcmCertificateArn:
Type: String
Description: "The certificate ARN for the domain name provided, must be in us-east-1 region"
Default: ""
Client:
Type: String
Default: "b10cks"
NuxtPublicFrontendUrl:
Type: String
Default: "https://www.b10cks.com"
NuxtB10cksAccessToken:
Type: String
Default: ""
NuxtB10cksApiUrl:
Type: String
Default: "https://api.b10cks.com/api"
NuxtIlumBaseUrl:
Type: String
Default: "https://api.b10cks.com/ilum"
NuxtPublicUmamiWebsiteId:
Type: String
Default: "824064d0-a59f-4db8-99fb-5a4ebc3e61a3"
NuxtPublicUmamiScriptUrl:
Type: String
Default: "https://insights.coderscantina.com/script.js"
Conditions:
IsDomainProvided: !Not [!Equals [!Ref DomainName, ""]]
ShouldAddWildcardSubdomains: !Equals [!Ref AddWildcardSubdomains, "True"]
HasClient: !Not [!Equals [!Ref Client, ""]]
Globals:
Function:
Runtime: nodejs24.x
Architectures:
- arm64
Environment:
Variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
NODE_OPTIONS: "--max-old-space-size=512"
Resources:
NuxtFunction:
Type: AWS::Serverless::Function
Properties:
Description: !Ref AWS::StackName
CodeUri: .output/server/
Handler: index.handler
MemorySize: 512
Timeout: 10
Environment:
Variables:
NUXT_B10CKS_ACCESS_TOKEN: !Ref NuxtB10cksAccessToken
NUXT_B10CKS_API_URL: !Ref NuxtB10cksApiUrl
NUXT_ILUM_BASE_URL: !Ref NuxtIlumBaseUrl
NUXT_PUBLIC_FRONTEND_URL: !Ref NuxtPublicFrontendUrl
NUXT_PUBLIC_UMAMI_WEBSITE_ID: !Ref NuxtPublicUmamiWebsiteId
NUXT_PUBLIC_UMAMI_SCRIPT_URL: !Ref NuxtPublicUmamiScriptUrl
NODE_ENV: production
NITRO_PRESET: aws-lambda
FunctionUrlConfig:
AuthType: NONE
Tags:
client: !If [HasClient, !Ref Client, !Ref AWS::StackName]
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub '${AWS::StackName}'
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
LifecycleConfiguration:
Rules:
- Id: DeleteIncompleteMultipartUploads
Status: Enabled
AbortIncompleteMultipartUpload:
DaysAfterInitiation: 1
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
CorsConfiguration:
CorsRules:
- AllowedHeaders: [ ]
AllowedMethods:
- "GET"
- "HEAD"
AllowedOrigins:
- "https://www.b10cks.com"
- "https://b10cks.com"
ExposedHeaders: [ ]
Tags:
- Key: client
Value: !If [HasClient, !Ref Client, !Ref AWS::StackName]
S3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Statement:
- Sid: AllowCloudFrontServicePrincipal
Effect: Allow
Principal:
Service: 'cloudfront.amazonaws.com'
Action: 's3:GetObject'
Resource:
- !Sub 'arn:aws:s3:::${S3Bucket}/*'
Condition:
StringEquals:
AWS:SourceArn: !Sub 'arn:aws:cloudfront::${AWS::AccountId}:distribution/${CloudFrontDistribution}'
CloudFrontOriginAccessControl:
Type: 'AWS::CloudFront::OriginAccessControl'
Properties:
OriginAccessControlConfig:
Name: !GetAtt S3Bucket.DomainName
Description: !Ref AWS::StackName
OriginAccessControlOriginType: s3
SigningBehavior: always
SigningProtocol: 'sigv4'
NuxtCachePolicy:
Type: 'AWS::CloudFront::CachePolicy'
Properties:
CachePolicyConfig:
Name: !Sub '${AWS::StackName}-Nuxt'
Comment: !Sub 'Cache Policy for AWS SAM Project ${AWS::StackName}'
DefaultTTL: 0
MaxTTL: 31536000
MinTTL: 0
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: none
EnableAcceptEncodingBrotli: true
EnableAcceptEncodingGzip: true
HeadersConfig:
HeaderBehavior: whitelist
Headers:
- 'Accept-Language'
- 'CloudFront-Viewer-Country'
QueryStringsConfig:
QueryStringBehavior: whitelist
QueryStrings:
- b10cks_rv
- b10cks_vid
NuxtApiCachePolicy:
Type: 'AWS::CloudFront::CachePolicy'
Properties:
CachePolicyConfig:
Name: !Sub '${AWS::StackName}-Nuxt-API'
Comment: !Sub 'Cache Policy for AWS SAM Project ${AWS::StackName} API'
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 0
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: none
EnableAcceptEncodingBrotli: true
EnableAcceptEncodingGzip: true
HeadersConfig:
HeaderBehavior: whitelist
Headers:
- 'Accept-Language'
- 'Authorization'
- 'CloudFront-Viewer-Country'
QueryStringsConfig:
QueryStringBehavior: all
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
Tags:
- Key: Name
Value: !Ref AWS::StackName
- Key: client
Value: !If [HasClient, !Ref Client, !Ref AWS::StackName]
DistributionConfig:
Comment: !Ref AWS::StackName
Enabled: true
PriceClass: PriceClass_100
HttpVersion: http2and3
IPV6Enabled: true
Aliases:
- !If [IsDomainProvided, !Ref DomainName, !Ref AWS::NoValue]
- !If [IsDomainProvided, !If [ShouldAddWildcardSubdomains, !Sub '*.${DomainName}', !Ref AWS::NoValue], !Ref AWS::NoValue]
ViewerCertificate:
Fn::If:
- IsDomainProvided
-
AcmCertificateArn: !If [IsDomainProvided, !Ref AcmCertificateArn, !Ref AWS::NoValue]
MinimumProtocolVersion: TLSv1.2_2021
SslSupportMethod: sni-only
-
CloudFrontDefaultCertificate: true
OriginGroups:
Quantity: 1
Items:
- Id: s3ThenNuxt
FailoverCriteria:
StatusCodes:
Quantity: 2
Items:
- 403
- 404
Members:
Quantity: 2
Items:
- OriginId: s3
- OriginId: nuxt
Origins:
- Id: nuxt
DomainName: !Select [ 2, !Split [ "/", !GetAtt NuxtFunctionUrl.FunctionUrl ] ]
CustomOriginConfig:
HTTPSPort: 443
OriginProtocolPolicy: https-only
OriginSSLProtocols:
- TLSv1.2
OriginKeepaliveTimeout: 5
OriginReadTimeout: 30
- Id: s3
DomainName: !GetAtt S3Bucket.RegionalDomainName
OriginAccessControlId: !Ref CloudFrontOriginAccessControl
S3OriginConfig:
OriginAccessIdentity: ''
DefaultCacheBehavior:
Compress: true
AllowedMethods:
- GET
- HEAD
- OPTIONS
CachedMethods:
- GET
- HEAD
- OPTIONS
TargetOriginId: s3ThenNuxt
ViewerProtocolPolicy: redirect-to-https
CachePolicyId: !Ref NuxtCachePolicy
OriginRequestPolicyId: b689b0a8-53d0-40ab-baf2-68738e2966ac # Managed-AllViewerExceptHostHeader
# Create custom policy to allow storyblok editor
# ResponseHeadersPolicyId: 67f7725c-6f97-4210-82d7-5512b31e9d03 # Managed-SecurityHeadersPolicy
CacheBehaviors:
- PathPattern: /_nuxt/*
TargetOriginId: s3
Compress: true
AllowedMethods:
- GET
- HEAD
- OPTIONS
CachedMethods:
- GET
- HEAD
- OPTIONS
ViewerProtocolPolicy: redirect-to-https
CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6 # Managed-CachingOptimized
OriginRequestPolicyId: 88a5eaf4-2fd4-4709-b370-b4c650ea3fcf # Managed-CORS-S3Origin
ResponseHeadersPolicyId: 67f7725c-6f97-4210-82d7-5512b31e9d03 # Managed-SecurityHeadersPolicy
- PathPattern: /api/*
TargetOriginId: nuxt
Compress: true
AllowedMethods:
- GET
- HEAD
- OPTIONS
- PUT
- POST
- PATCH
- DELETE
CachedMethods:
- GET
- HEAD
- OPTIONS
ViewerProtocolPolicy: redirect-to-https
CachePolicyId: !Ref NuxtApiCachePolicy
OriginRequestPolicyId: b689b0a8-53d0-40ab-baf2-68738e2966ac # Managed-AllViewerExceptHostHeader
ResponseHeadersPolicyId: 67f7725c-6f97-4210-82d7-5512b31e9d03 # Managed-SecurityHeadersPolicy
CustomErrorResponses:
- ErrorCode: 502
ResponsePagePath: /error.html
ResponseCode: 502
ErrorCachingMinTTL: 10
- ErrorCode: 503
ResponsePagePath: /error.html
ResponseCode: 503
ErrorCachingMinTTL: 10
Outputs:
S3Bucket:
Description: "The S3 bucket that contains static files"
Value: !Ref S3Bucket
CloudFrontDistribution:
Description: "The CloudFront distribution in front of the S3 bucket"
Value: !Ref CloudFrontDistribution
WebsiteUrl:
Description: "The website URL"
Value: !If [IsDomainProvided, !Sub "https://www.${DomainName}/", !Sub "https://${CloudFrontDistribution.DomainName}/"]
ApplicationLog:
Description: "The CloudWatch log group where application log are saved"
Value: !Sub "/aws/lambda/${NuxtFunction}"