-
Notifications
You must be signed in to change notification settings - Fork 1
/
serverless.yml
435 lines (389 loc) · 10.6 KB
/
serverless.yml
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
service: barracao-digital
app: barracao-digital
org: rodrigogs
plugins:
- serverless-bundle
- serverless-offline
- serverless-finch
- serverless-domain-manager
package:
individually: true
custom:
stage: ${opt:stage, env:STAGE, env:NODE_ENV, 'development'}
region: ${opt:region, 'sa-east-1'}
bundle:
externals:
- aws-sdk
forceExclude:
- '@firebase/app'
- firebase-admin
linting: true
sourcemaps: true
client:
bucketName: ${self:service}-${self:provider.stage}-webapp
distributionFolder: frontend/dist
customDomain:
domainName: api.barracaodigital.com
basePath: ${self:provider.stage}
stage: ${self:provider.stage}
certificateName: '*.barracaodigital.com'
createRoute53Record: true
# Tables
configsTableName: ${self:service}-${self:provider.stage}-configs-table
doctorsTableName: ${self:service}-${self:provider.stage}-doctors-table
patientsTableName: ${self:service}-${self:provider.stage}-patients-table
facilitiesTableName: ${self:service}-${self:provider.stage}-facilities-table
provider:
name: aws
runtime: nodejs12.x
memorySize: 256
stage: ${self:custom.stage}
region: ${self:custom.region}
versionFunctions: false
logRetentionInDays: 5
stackTags:
STACK: ${self:service}
STAGE: ${self:custom.stage}
REGION: ${self:custom.region}
iamRoleStatements:
- Effect: Allow
Action:
- 'logs:*'
Resource: '*'
- Effect: Allow
Action:
- 'dynamodb:*'
Resource: 'arn:aws:dynamodb:${self:custom.region}:${file(./serverless.js):getAccountId}:table/${self:service}-${self:custom.stage}-*'
- Effect: Allow
Action:
- 'events:*'
Resource: 'arn:aws:events:${self:custom.region}:${file(./serverless.js):getAccountId}:rule/*'
- Effect: Allow
Action:
- 'lambda:*'
Resource: '*'
- Effect: Allow
Action:
- 'sns:*'
Resource: '*'
# serverless_domain_manager pemissions
- Effect: Allow
Action:
- 'acm:ListCertificates'
Resource: '*'
- Effect: Allow
Action:
- 'apigateway:*'
Resource: '*'
- Effect: Allow
Action:
- 'cloudformation:*'
Resource: '*'
- Effect: Allow
Action:
- 'route53:*'
Resource: '*'
- Effect: Allow
Action:
- 'iam:CreateServiceLinkedRole'
Resource: '*'
- Effect: 'Allow'
Action:
- 's3:*'
Resource: 'arn:aws:s3:::barracao-digital-${self:custom.stage}-conversation-files-bucket/*'
deploymentBucket:
name: ${self:service}-deploys
maxPreviousDeploymentArtifacts: 10 # On every deployment the framework prunes the bucket to remove artifacts older than this limit. The default is 5
blockPublicAccess: true # Prevents public access via ACLs or bucket policies. Default is false
environment:
AWS_ACCOUNT_ID: ${file(./serverless.js):getAccountId}
STACK_NAME: ${self:service}
STAGE: ${self:custom.stage}
APP_URL: ${env:APP_URL}
TELEGRAM_TOKEN: ${env:TELEGRAM_TOKEN}
GOOGLE_APPLICATION_CREDENTIALS: ${env:GOOGLE_APPLICATION_CREDENTIALS}
DOCTOR_INACTIVITY_TIMEOUT_IN_MINUTES: ${env:DOCTOR_INACTIVITY_TIMEOUT_IN_MINUTES, '35'}
CONFIGS_TABLE: ${self:custom.configsTableName}
DOCTORS_TABLE: ${self:custom.doctorsTableName}
PATIENTS_TABLE: ${self:custom.patientsTableName}
FACILITIES_TABLE: ${self:custom.facilitiesTableName}
layers:
common:
path: layers/common
functions:
# Jobs
alternate-doctor-job:
handler: functions/jobs/alternate-doctor-job.handler
memorySize: 1024
timeout: 30
layers:
- {Ref: CommonLambdaLayer}
# Authorizers
doctorAuthorizer:
handler: functions/api/doctor-authorizer.handler
layers:
- {Ref: CommonLambdaLayer}
adminAuthorizer:
handler: functions/api/admin-authorizer.handler
layers:
- {Ref: CommonLambdaLayer}
masterAuthorizer:
handler: functions/api/master-authorizer.handler
layers:
- {Ref: CommonLambdaLayer}
# API
healthcheck:
handler: functions/api/healthcheck.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: GET
path: /
cors: true
# Auth
auth:
handler: functions/api/auth.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: POST
path: /auth/login
cors: true
# Doctors
doctorsGet:
handler: functions/api/doctors/get.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: GET
path: /doctors
cors: true
authorizer: adminAuthorizer
- http:
method: GET
path: /doctors/cep/{cep}
cors: true
authorizer: doctorAuthorizer
- http:
method: GET
path: /doctors/username/{username}
cors: true
authorizer: doctorAuthorizer
doctorsPost:
handler: functions/api/doctors/post.handler
layers:
- {Ref: CommonLambdaLayer}
memorySize: 512
timeout: 30
events:
- http:
method: POST
path: /doctors
cors: true
authorizer: adminAuthorizer
- http:
method: POST
path: /doctors/alternate
cors: true
authorizer: doctorAuthorizer
- http:
method: POST
path: /doctors/conversation/{ticket}
cors: true
authorizer: doctorAuthorizer
doctorsPut:
handler: functions/api/doctors/put.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: PUT
path: /doctors/{username}
cors: true
authorizer: doctorAuthorizer
doctorsDelete:
handler: functions/api/doctors/delete.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: DELETE
path: /doctors/{username}
cors: true
authorizer: masterAuthorizer
- http:
method: DELETE
path: /doctors/conversation/{ticket}
cors: true
authorizer: doctorAuthorizer
# Patients
patientsGet:
handler: functions/api/patients/get.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: GET
path: /patients/cep/{cep}
cors: true
authorizer: doctorAuthorizer
- http:
method: GET
path: /patients/ticket/{ticket}
cors: true
patientsPost:
handler: functions/api/patients/post.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: POST
path: /patients
cors: true
patientsPut:
handler: functions/api/patients/put.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: PUT
path: /patients/{ticket}
cors: true
authorizer: masterAuthorizer
- http:
method: PUT
path: /patients/{ticket}/feedback
cors: true
- http:
method: PUT
path: /patients/{ticket}/status/ongoing
cors: true
authorizer: doctorAuthorizer
- http:
method: PUT
path: /patients/{ticket}/status/waiting_kit
cors: true
authorizer: doctorAuthorizer
- http:
method: PUT
path: /patients/{ticket}/status/received_kit
cors: true
- http:
method: PUT
path: /patients/{ticket}/status/sent_kit
cors: true
- http:
method: PUT
path: /patients/{ticket}/status/finished
cors: true
authorizer: doctorAuthorizer
- http:
method: PUT
path: /patients/{ticket}/status/gave_up
cors: true
- http:
method: PUT
path: /patients/{ticket}/messaging/token
cors: true
- http:
method: PUT
path: /patients/{ticket}/messaging/sms
cors: true
authorizer: doctorAuthorizer
- http:
method: PUT
path: /patients/{ticket}/upload/file
cors: true
- http:
method: PUT
path: /patients/{ticket}/download/file
cors: true
patientsDelete:
handler: functions/api/patients/delete.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: DELETE
path: /patients/{ticket}/video
cors: true
# Facilities
facilitiesGet:
handler: functions/api/facilities/get.handler
layers:
- {Ref: CommonLambdaLayer}
memorySize: 1024
timeout: 30
events:
- http:
method: GET
path: /facilities
cors: true
authorizer: masterAuthorizer
- http:
method: GET
path: /facilities/origin/{origin}
cors: true
- http:
method: GET
path: /facilities/origin/{origin}/destinations
cors: true
authorizer: masterAuthorizer
- http:
method: GET
path: /facilities/origin/{origin}/check
cors: true
facilitiesPost:
handler: functions/api/facilities/post.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: POST
path: /facilities
cors: true
authorizer: masterAuthorizer
facilitiesPut:
handler: functions/api/facilities/put.handler
layers:
- {Ref: CommonLambdaLayer}
memorySize: 1024
timeout: 30
events:
- http:
method: PUT
path: /facilities/{origin}
cors: true
authorizer: masterAuthorizer
facilitiesDelete:
handler: functions/api/facilities/delete.handler
layers:
- {Ref: CommonLambdaLayer}
events:
- http:
method: DELETE
path: /facilities/{origin}
cors: true
authorizer: masterAuthorizer
- http:
method: DELETE
path: /facilities/{origin}/destinations
cors: true
authorizer: masterAuthorizer
resources:
- ${file(resources/api-gateway-cf-resources.yml)}
- ${file(resources/cloudfront-cf-resources.yml)}
- ${file(resources/dynamodb-cf-resources.yml)}
- ${file(resources/s3-bucket-cf-resources.yml)}
- Outputs:
FacilitiesDeleteLambdaFunctionQualifiedArn:
Description: ARN of the FacilitiesDelete lambda function
Value: !GetAtt FacilitiesDeleteLambdaFunction.Arn
CommonLambdaLayerArn:
Description: The ARN of the common lambda layer
Value: !Ref CommonLambdaLayer
Export:
Name: ${self:custom.stage}-common-lambda-layer-arn