-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserverless.yml
More file actions
439 lines (412 loc) · 13.7 KB
/
Copy pathserverless.yml
File metadata and controls
439 lines (412 loc) · 13.7 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
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
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: abstract-play
# app and org for use with dashboard.serverless.com
# app: apfront
# org: wamelen
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
frameworkVersion: '3'
custom:
scheduleEnabled:
prod: true
dev: false
testBotEnabled:
dev: true
prod: false
recbucket:
prod: "records.abstractplay.com"
dev: "records.abstractplay.com"
dumpbucket: "abstractplay-db-dump"
websocketDomain:
Fn::Join:
- ""
- - Ref: WebsocketsApi
- ".execute-api."
- Ref: AWS::Region
- ".amazonaws.com"
stageConfig:
dev:
profile: AbstractPlayDev
userpool: arn:aws:cognito-idp:us-east-1:153672715141:userpool/us-east-1_2zrzbEjoU
userpoolId: us-east-1_2zrzbEjoU
userpoolClient: 14mpql1tmvntup4p2anm4jt782
botpool: arn:aws:cognito-idp:us-east-1:153672715141:userpool/us-east-1_kqlqXHDJ5
botpoolId: us-east-1_kqlqXHDJ5
botTokenUrl: https://abstract-play-bots-dev.auth.us-east-1.amazoncognito.com/oauth2/token
botOAuthScope: default-m2m-resource-server-dev/communicate
sqsurl: https://sqs.us-east-1.amazonaws.com/153672715141/abstractplay-aiai-dev-aiai-queue
wsDomain: qwmw4fb0l6.execute-api.us-east-1.amazonaws.com
wsSqs: https://sqs.us-east-1.amazonaws.com/153672715141/abstractplay-ws-messages-dev
prod:
profile: AbstractPlayProd
userpool: arn:aws:cognito-idp:us-east-1:153672715141:userpool/us-east-1_YCjgSZHJm
userpoolId: us-east-1_YCjgSZHJm
userpoolClient: 2isan3ctk1aabt2v6r6aptlpg
botpool: arn:aws:cognito-idp:us-east-1:153672715141:userpool/us-east-1_nEKyig64I
botpoolId: us-east-1_nEKyig64I
botTokenUrl: https://botauth.abstractplay.com/oauth2/token
botOAuthScope: default-m2m-resource-server-zssvzy/communicate
sqsurl: https://sqs.us-east-1.amazonaws.com/153672715141/abstractplay-aiai-prod-aiai-queue
wsDomain: qwmw4fb0l6.execute-api.us-east-1.amazonaws.com
wsSqs: https://sqs.us-east-1.amazonaws.com/153672715141/abstractplay-ws-messages-prod
package:
# individually: true
excludeDevDependencies: false
exclude:
- node_modules/@aws-sdk/**
plugins:
- serverless-plugin-common-excludes
- serverless-plugin-include-dependencies
provider:
name: aws
runtime: nodejs20.x
versionFunctions: false
stage: ${opt:stage, 'dev'}
profile: ${self:custom.stageConfig.${self:provider.stage}.profile}
region: us-east-1
logs:
websocket: true
environment:
ABSTRACT_PLAY_TABLE: abstract-play-${self:provider.stage}
userpool: ${self:custom.stageConfig.${self:provider.stage}.userpool}
userpoolId: ${self:custom.stageConfig.${self:provider.stage}.userpoolId}
userpoolClient: ${self:custom.stageConfig.${self:provider.stage}.userpoolClient}
BOTPOOL_ID: ${self:custom.stageConfig.${self:provider.stage}.botpoolId}
SQS_URL: ${self:custom.stageConfig.${self:provider.stage}.sqsurl}
AIAI_USERID: SkQfHAjeDxs8eeEnScuYA
WEBSOCKET_DOMAIN: ${self:custom.stageConfig.${self:provider.stage}.wsDomain}
WEBSOCKET_STAGE: ${self:provider.stage}
WEBSOCKET_SQS: ${self:custom.stageConfig.${self:provider.stage}.wsSqs}
TOTP_KEY: ${env:TOTP_KEY}
VAPID_PRIVATE_KEY: ${env:VAPID_PRIVATE_KEY}
VAPID_PUBLIC_KEY: ${env:VAPID_PUBLIC_KEY}
OPENSSH_PRIVATE_KEY: ${env:OPENSSH_PRIVATE_KEY}
BOT_OUTBOUND_QUEUE_URL:
Ref: BotOutboundQueue
BOT_TOKEN_URL: ${self:custom.stageConfig.${self:provider.stage}.botTokenUrl}
BOT_OAUTH_SCOPE: ${self:custom.stageConfig.${self:provider.stage}.botOAuthScope}
TEST_BOT_CLIENT_ID: ${env:TEST_BOT_CLIENT_ID, ''}
TEST_BOT_CLIENT_SECRET: ${env:TEST_BOT_CLIENT_SECRET, ''}
API_BASE_URL:
Fn::Join:
- ''
- - 'https://'
- Ref: ApiGatewayRestApi
- '.execute-api.'
- Ref: AWS::Region
- '.amazonaws.com/'
- ${self:provider.stage}
BOT_QUERY_URL:
Fn::Join:
- ''
- - 'https://'
- Ref: ApiGatewayRestApi
- '.execute-api.'
- Ref: AWS::Region
- '.amazonaws.com/'
- ${self:provider.stage}
- '/botQuery'
# TOTP_KEY: ${file(../apsecrets.yml):totp_key}
# VAPID_PRIVATE_KEY: ${file(../apsecrets.yml):vapid_private_key}
# VAPID_PUBLIC_KEY: ${file(../apsecrets.yml):vapid_public_key}
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:ExportTableToPointInTime
- dynamodb:BatchWriteItem
- ses:SendEmail
- ses:SendRawEmail
- sqs:SendMessage
- cloudfront:CreateInvalidation
Resource: "*"
- Effect: 'Allow'
Action:
- 's3:ListBucket'
Resource:
- 'arn:aws:s3:::abstractplay-db-dump'
- 'arn:aws:s3:::records.abstractplay.com'
- Effect: 'Allow'
Action:
- 's3:GetObject'
- 's3:PutObject'
Resource:
- 'arn:aws:s3:::abstractplay-db-dump/*'
- 'arn:aws:s3:::records.abstractplay.com/*'
- Effect: Allow
Action:
- cognito-idp:AdminCreateUser
- cognito-idp:AdminDeleteUser
- cognito-idp:CreateUserPoolClient
- cognito-idp:DeleteUserPoolClient
- cognito-idp:ListUserPoolClientSecrets
- cognito-idp:AddUserPoolClientSecret
- cognito-idp:DeleteUserPoolClientSecret
Resource:
- ${self:custom.stageConfig.dev.botpool}
- ${self:custom.stageConfig.prod.botpool}
resources:
Resources:
# One table design
AbstractGamesDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
-
AttributeName: "pk"
AttributeType: "S"
-
AttributeName: "sk"
AttributeType: "S"
KeySchema:
-
AttributeName: "pk"
KeyType: "HASH"
-
AttributeName: "sk"
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
StreamSpecification:
StreamViewType: "NEW_AND_OLD_IMAGES"
TableName: ${self:provider.environment.ABSTRACT_PLAY_TABLE}
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
WsMessageQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: abstractplay-ws-messages-${self:provider.stage}
VisibilityTimeout: 900 # match your consumer Lambda timeout
MessageRetentionPeriod: 86400 # 1 day, adjust as needed
BotOutboundQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: abstractplay-bot-outbound-${self:provider.stage}
VisibilityTimeout: 60
MessageRetentionPeriod: 86400
# Apparently this is explicitly needed (which makes no sense to me, but there it is)
ConnectLambdaPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: ${self:service}-${self:provider.stage}-connect
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn:
Fn::Sub: arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${WebsocketsApi}/${self:provider.stage}/*/$connect
DisconnectLambdaPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: ${self:service}-${self:provider.stage}-disconnect
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn:
Fn::Sub: arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${WebsocketsApi}/${self:provider.stage}/*/$disconnect
# for autodeployments
# WebsocketsDeployment:
# Type: AWS::ApiGatewayV2::Deployment
# Properties:
# ApiId:
# Ref: WebsocketsApi
# Description: Force redeploy ${sls:instanceId}
# DependsOn:
# - SconnectWebsocketsRoute
# - SdisconnectWebsocketsRoute
# WebsocketsDeploymentStage:
# Type: AWS::ApiGatewayV2::Stage
# Properties:
# StageName: ${self:provider.stage}
# Description: Redeploy ${sls:instanceId} # forces stage update
# ApiId: !Ref WebsocketsApi
# DeploymentId: !Ref WebsocketsDeployment
# DefaultRouteSettings:
# DataTraceEnabled: true # enables execution logging
# LoggingLevel: INFO # ERROR | INFO
Outputs:
WsMessageQueueArn:
Value: !GetAtt WsMessageQueue.Arn
Export:
Name: WsMessageQueueArn-${self:provider.stage}
WsMessageQueueUrl:
Value: !Ref WsMessageQueue
Export:
Name: WsMessageQueueUrl-${self:provider.stage}
WebSocketApiDomainName:
Value:
Fn::Join:
- ""
- - Ref: WebsocketsApi
- ".execute-api."
- Ref: AWS::Region
- ".amazonaws.com"
WebsocketApiUrl:
Value:
Fn::Join:
- ""
- - "wss://"
- Ref: WebsocketsApi
- ".execute-api."
- Ref: AWS::Region
- ".amazonaws.com/"
- ${self:provider.stage}
Export:
Name: ${self:service}-${self:provider.stage}-WebsocketApiUrl
functions:
authQuery:
handler: api/abstractplay.authQuery
memorySize: 1024
description: Abstract Play queries that need authorization.
logRetentionInDays: 30
events:
- http:
path: authQuery
method: post
cors: true
integration: lambda
authorizer:
name: authorizer
arn: ${self:provider.environment.userpool}
claims:
- email
- 'cognito:username'
botQuery:
handler: api/abstractplay.botQuery
memorySize: 1024
description: Abstract Play queries for bots.
logRetentionInDays: 30
events:
- http:
path: botQuery
method: post
cors: true
integration: lambda
authorizer:
name: botAuthorizer
arn: ${self:custom.stageConfig.${self:provider.stage}.botpool}
scopes:
- ${self:custom.stageConfig.${self:provider.stage}.botOAuthScope}
query:
handler: api/abstractplay.query
memorySize: 256
description: Abstract Play queries that does not need authorization.
logRetentionInDays: 30
events:
- http:
path: query
method: get
cors: true
- http:
path: query
method: post
cors: true
testBot:
handler: api/testBot.handler
memorySize: 256
description: Dev-only reference bot — full source and docs in api/testBot.ts
logRetentionInDays: 30
events:
- http:
path: testBot
method: get
cors: true
enabled: ${self:custom.testBotEnabled.${self:provider.stage}}
- http:
path: testBot
method: post
cors: true
enabled: ${self:custom.testBotEnabled.${self:provider.stage}}
yourturn:
handler: utils/yourturn.handler
description: Sends out "your turn" notifications
logRetentionInDays: 30
events:
- eventBridge:
name: abstractplay-${self:provider.stage}-yourturn
description: Send out "your turn" notifications
enabled: ${self:custom.scheduleEnabled.${self:provider.stage}}
schedule: cron(0 14,22 * * ? *)
bot-outbound:
handler: utils/bot-outbound.handler
description: Contacts bot HTTPS endpoints for challenges and move notifications
timeout: 60
memorySize: 512
logRetentionInDays: 30
events:
- sqs:
arn:
Fn::GetAtt:
- BotOutboundQueue
- Arn
batchSize: 1
# websocket functions
# wsAuthorizer:
# name: wsAuthorizer
# handler: api/sockets/wsAuthorizer.wsAuthorizer
# logRetentionInDays: 7
connect:
handler: api/sockets/connectHandler.handler
logRetentionInDays: 7
timeout: 30
events:
- websocket:
route: $connect
# authorizer:
# name: wsAuthorizer
# identitySource: route.request.header.Sec-WebSocket-Protocol
disconnect:
handler: api/sockets/disconnectHandler.handler
timeout: 30
logRetentionInDays: 7
events:
- websocket:
route: $disconnect
subscribe:
handler: api/sockets/authHandler.handler
logRetentionInDays: 7
timeout: 30
events:
- websocket:
route: subscribe
messageHandler:
handler: api/sockets/messageHandler.handler
logRetentionInDays: 7
timeout: 30
environment:
DOMAIN_NAME: ${self:custom.websocketDomain}
STAGE: ${self:provider.stage}
events:
- sqs:
arn:
Fn::GetAtt:
- WsMessageQueue
- Arn
# scratch:
# handler: utils/scratch.handler
# description: For testing only
# timeout: 60