-
Notifications
You must be signed in to change notification settings - Fork 11
/
template.yaml
523 lines (496 loc) · 15.2 KB
/
template.yaml
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Frontend Service Discovery on AWS (uksb-1tthgi8k7) (version:v1.3)
Globals:
Function:
Runtime: nodejs16.x
Architectures:
- arm64
Tracing: Active
Parameters:
Stage:
Type: String
Default: prod
LogLevel:
Type: String
Default: INFO
AllowedValues:
- CRITICAL
- FATAL
- ERROR
- WARNING
- INFO
- DEBUG
- NOTSET
AccessControlAllowOrigin:
Type: String
Description: The cors configuration for allow-origin for the consumer API. Specify a domain or * to allow all.
DefaultUserEmail:
Type: String
Default: ""
Description: Optional email for the default user for the Admin API. Leave blank to skip creation
CognitoAdvancedSecurity:
Description: The type of Cognito advanced security to enable. Disabled by default.
Type: String
Default: "OFF"
AllowedValues:
- "OFF"
- "AUDIT"
- "ENFORCED"
CookieSettings:
Description: Settings to be applied when setting cookies via Set-Cookie header
Type: String
Default: Secure
DeleteExpiryMinutes:
Description: The number of minutes deleted data will be retained.
Type: Number
Default: 1440
EnableDynamoDBBackups:
Description: Whether to enable point in time recovery for the DynamoDB tables
Type: String
Default: "false"
AllowedValues:
- "true"
- "false"
Conditions:
CreateUser: !Not [!Equals [!Ref DefaultUserEmail, ""]]
Mappings:
Solution:
Constants:
Version: '1.3'
Resources:
ProjectStore:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: "projectId"
AttributeType: "S"
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: "projectId"
KeyType: "HASH"
StreamSpecification:
StreamViewType: NEW_IMAGE
TimeToLiveSpecification:
AttributeName: "expiresAt"
Enabled: true
SSESpecification:
KMSMasterKeyId: alias/aws/dynamodb
SSEEnabled: true
SSEType: KMS
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: !Ref EnableDynamoDBBackups
FrontendStore:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: "projectId"
AttributeType: "S"
- AttributeName: "microFrontendId"
AttributeType: "S"
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: "projectId"
KeyType: "HASH"
- AttributeName: "microFrontendId"
KeyType: "RANGE"
StreamSpecification:
StreamViewType: NEW_IMAGE
TimeToLiveSpecification:
AttributeName: "expiresAt"
Enabled: true
SSESpecification:
KMSMasterKeyId: alias/aws/dynamodb
SSEEnabled: true
SSEType: KMS
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: !Ref EnableDynamoDBBackups
ConsumerViewStore:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: "projectId"
AttributeType: "S"
- AttributeName: "microFrontendId"
AttributeType: "S"
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: "projectId"
KeyType: "HASH"
- AttributeName: "microFrontendId"
KeyType: "RANGE"
SSESpecification:
KMSMasterKeyId: alias/aws/dynamodb
SSEEnabled: true
SSEType: KMS
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: !Ref EnableDynamoDBBackups
DeploymentStore:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: "deploymentId"
AttributeType: "S"
- AttributeName: "sk"
AttributeType: "S"
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: "deploymentId"
KeyType: "HASH"
- AttributeName: "sk"
KeyType: "RANGE"
TimeToLiveSpecification:
AttributeName: "expiresAt"
Enabled: true
SSESpecification:
KMSMasterKeyId: alias/aws/dynamodb
SSEEnabled: true
SSEType: KMS
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: !Ref EnableDynamoDBBackups
VersionStore:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: "microFrontendId"
AttributeType: "S"
- AttributeName: "version"
AttributeType: "S"
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: "microFrontendId"
KeyType: "HASH"
- AttributeName: "version"
KeyType: "RANGE"
TimeToLiveSpecification:
AttributeName: "expiresAt"
Enabled: true
SSESpecification:
KMSMasterKeyId: alias/aws/dynamodb
SSEEnabled: true
SSEType: KMS
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: !Ref EnableDynamoDBBackups
ConsumerApi:
Type: AWS::Serverless::Api
Properties:
Name: Frontend Service Discovery Consumer API
StageName: !Ref Stage
Cors: !Sub "'${AccessControlAllowOrigin}'"
TracingEnabled: true
StreamHandler:
Type: AWS::Serverless::Function
Properties:
CodeUri: infrastructure/lambda/stream
Handler: app.handler
Timeout: 60
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
REGION: !Ref "AWS::Region"
POWERTOOLS_SERVICE_NAME: streamHandler
CONSUMER_STORE: !Ref ConsumerViewStore
PROJECT_STORE: !Ref ProjectStore
FRONTEND_STORE: !Ref FrontendStore
VERSION_STORE: !Ref VersionStore
ALLOW_ORIGIN: !Ref AccessControlAllowOrigin
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref ConsumerViewStore
- DynamoDBReadPolicy:
TableName: !Ref ProjectStore
- DynamoDBCrudPolicy:
TableName: !Ref FrontendStore
- DynamoDBCrudPolicy:
TableName: !Ref VersionStore
Events:
ProjectStream:
Type: DynamoDB
Properties:
Stream: !GetAtt ProjectStore.StreamArn
StartingPosition: TRIM_HORIZON
Enabled: true
FilterCriteria:
Filters:
- Pattern: '{"userIdentity": [ { "exists": false } ]}'
FrontendStream:
Type: DynamoDB
Properties:
Stream: !GetAtt FrontendStore.StreamArn
StartingPosition: TRIM_HORIZON
Enabled: true
FilterCriteria:
Filters:
- Pattern: '{"userIdentity": [ { "exists": false } ]}'
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: false
Target: "es2020"
Sourcemap: false
EntryPoints:
- app.js
ConsumerHandler:
Type: AWS::Serverless::Function
Properties:
CodeUri: infrastructure/lambda/consumerApi
Handler: app.handler
Timeout: 10
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
REGION: !Ref "AWS::Region"
POWERTOOLS_SERVICE_NAME: consumerApi
CONSUMER_STORE: !Ref ConsumerViewStore
ALLOW_ORIGIN: !Ref AccessControlAllowOrigin
COOKIE_SETTINGS: !Ref CookieSettings
Policies:
- DynamoDBReadPolicy:
TableName: !Ref ConsumerViewStore
Events:
Any:
Type: Api
Properties:
Path: /projects/{projectId}/microFrontends
Method: GET
RestApiId: !Ref ConsumerApi
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: false
Target: "es2020"
Sourcemap: false
EntryPoints:
- app.js
UserPool:
Type: AWS::Cognito::UserPool
Properties:
AdminCreateUserConfig:
AllowAdminCreateUserOnly: true
InviteMessageTemplate:
EmailMessage: "Your Frontend Service Discovery username is {username} and the temporary password is {####}"
EmailSubject: "Your temporary password for Frontend Service Discovery"
AutoVerifiedAttributes:
- email
UserPoolAddOns:
AdvancedSecurityMode: !Ref CognitoAdvancedSecurity
Policies:
PasswordPolicy:
MinimumLength: 8
RequireLowercase: true
RequireNumbers: true
RequireSymbols: true
RequireUppercase: true
UserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
UserPoolId: !Ref UserPool
IdTokenValidity: 1
AccessTokenValidity: 1
RefreshTokenValidity: 1
TokenValidityUnits:
AccessToken: hours
IdToken: hours
RefreshToken: days
SupportedIdentityProviders:
- COGNITO
ExplicitAuthFlows:
- ALLOW_ADMIN_USER_PASSWORD_AUTH
- ALLOW_REFRESH_TOKEN_AUTH
CognitoUserPoolAdmin:
Condition: CreateUser
Type: AWS::Cognito::UserPoolUser
Properties:
Username: !Ref DefaultUserEmail
DesiredDeliveryMediums:
- EMAIL
UserPoolId: !Ref UserPool
UserAttributes:
- Name: email
Value: !Ref DefaultUserEmail
- Name: email_verified
Value: "True"
AdminAPI:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref Stage
TracingEnabled: true
Name: Frontend Service Discovery Admin API
Auth:
AddDefaultAuthorizerToCorsPreflight: false
DefaultAuthorizer: Cognito
Authorizers:
Cognito:
UserPoolArn: !GetAtt UserPool.Arn
AdminAPIHandler:
Type: AWS::Serverless::Function
Properties:
CodeUri: infrastructure/lambda/adminApi
Handler: app.handler
Timeout: 10
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
ACCOUNT_ID: !Ref "AWS::AccountId"
REGION: !Ref "AWS::Region"
POWERTOOLS_SERVICE_NAME: AdminAPI
PROJECT_STORE: !Ref ProjectStore
FRONTEND_STORE: !Ref FrontendStore
DEPLOYMENT_STORE: !Ref DeploymentStore
VERSION_STORE: !Ref VersionStore
DEPLOYMENT_STATE_MACHINE_ARN: !Ref DeploymentStateMachine
DEPLOYMENT_STATE_MACHINE_NAME: !GetAtt DeploymentStateMachine.Name
DELETE_EXPIRY_MINUTES: !Ref DeleteExpiryMinutes
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref ProjectStore
- DynamoDBCrudPolicy:
TableName: !Ref FrontendStore
- DynamoDBCrudPolicy:
TableName: !Ref DeploymentStore
- DynamoDBCrudPolicy:
TableName: !Ref VersionStore
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- states:StartExecution
Resource: !Ref DeploymentStateMachine
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- states:StopExecution
Resource: !Sub "arn:aws:states:${AWS::Region}:${AWS::AccountId}:execution:${DeploymentStateMachine.Name}:*"
Events:
GetProjects:
Type: Api
Properties:
Path: /projects
Method: GET
RestApiId: !Ref AdminAPI
PostProjects:
Type: Api
Properties:
Path: /projects
Method: POST
RestApiId: !Ref AdminAPI
PatchProject:
Type: Api
Properties:
Path: /projects/{projectId}
Method: PATCH
RestApiId: !Ref AdminAPI
DeleteProject:
Type: Api
Properties:
Path: /projects/{projectId}
Method: DELETE
RestApiId: !Ref AdminAPI
DeleteMicroFrontend:
Type: Api
Properties:
Path: /projects/{projectId}/microFrontends/{microFrontendId}
Method: DELETE
RestApiId: !Ref AdminAPI
GetMicroFrontends:
Type: Api
Properties:
Path: /projects/{projectId}/microFrontends
Method: GET
RestApiId: !Ref AdminAPI
GetMicroFrontendVersions:
Type: Api
Properties:
Path: /projects/{projectId}/microFrontends/{microFrontendId}/versions
Method: GET
RestApiId: !Ref AdminAPI
PostMicroFrontends:
Type: Api
Properties:
Path: /projects/{projectId}/microFrontends
Method: POST
RestApiId: !Ref AdminAPI
PatchMicroFrontend:
Type: Api
Properties:
Path: /projects/{projectId}/microFrontends/{microFrontendId}
Method: PATCH
RestApiId: !Ref AdminAPI
PostMicroFrontendVersion:
Type: Api
Properties:
Path: /projects/{projectId}/microFrontends/{microFrontendId}/versions
Method: POST
RestApiId: !Ref AdminAPI
PostDeployment:
Type: Api
Properties:
Path: /projects/{projectId}/microFrontends/{microFrontendId}/deployment
Method: POST
RestApiId: !Ref AdminAPI
DeleteDeployment:
Type: Api
Properties:
Path: /projects/{projectId}/microFrontends/{microFrontendId}/deployment/{deploymentId}
Method: DELETE
RestApiId: !Ref AdminAPI
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: false
Target: "es2020"
Sourcemap: false
EntryPoints:
- app.js
StateMachineRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: !Sub "states.${AWS::Region}.amazonaws.com"
Action: "sts:AssumeRole"
Policies:
- PolicyName: dynamodb
PolicyDocument:
Statement:
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:UpdateItem
Resource:
- !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${FrontendStore}
- !GetAtt DeploymentStore.Arn
DeploymentStateMachine:
Type: AWS::StepFunctions::StateMachine
Properties:
Definition:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: infrastructure/stepfunctions/deploymentASL.json
RoleArn: !GetAtt StateMachineRole.Arn
Outputs:
ConsumerApi:
Description: "Consumer Api API Gateway endpoint URL"
Value: !Sub "https://${ConsumerApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}"
AdminApi:
Description: "Admin API Gateway endpoint URL"
Value: !Sub "https://${AdminAPI}.execute-api.${AWS::Region}.amazonaws.com/${Stage}"
CognitoUserPoolArn:
Description: Cognito User Pool Arn
Value: !GetAtt UserPool.Arn
CognitoUserPoolID:
Description: Cognito User Pool Id
Value: !Ref UserPool
CognitoWebClientID:
Description: Cognito User Pool Client Id
Value: !Ref UserPoolClient
Region:
Description: The AWS region where the infrastructure is deployed
Value: !Ref "AWS::Region"
SolutionVersion:
Value: !FindInMap [Solution, Constants, Version]