-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
357 lines (334 loc) · 10.9 KB
/
serverless.yml
File metadata and controls
357 lines (334 loc) · 10.9 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
org: lucasbrogni
app: zero-trust-file-apis
service: zero-trust-confidential-files-api
provider:
name: aws
runtime: nodejs20.x
stage: ${opt:stage, 'dev'}
environment:
USER_TABLE_NAME: Users-${self:provider.stage}
RESEND_API_KEY: ${param:resendApiKey}
MFA_CODE_TABLE_NAME: MfaCodes-${self:provider.stage}
MFA_TTL_SECONDS: 300
JWT_SECRET: ${param:jwtSecret}
EMAIL_FROM: ${param:emailFrom}
S3_UPLOAD_BUCKET_NAME: ${param:s3UploadBucketName}-${self:provider.stage}
S3_PRESIGNED_URL_EXPIRATION: 300
GEMINI_API_KEY: ${param:geminiApiKey}
GEMINI_API_URL: ${param:geminiApiURL}
INVOICES_TABLE_NAME: Invoices-${self:provider.stage}
httpApi:
authorizers:
authorizer:
type: request
identitySource: "$request.header.Authorization"
functionName: authorizer
enableSimpleResponses: true
functions:
signup:
handler: auth/signup.handler
events:
- httpApi:
path: /signup
method: post
role: SignupLambdaRole
signin:
handler: auth/signin.handler
events:
- httpApi:
path: /signin
method: post
role: SigninLambdaRole
verifyMfa:
handler: auth/verify-mfa.handler
events:
- httpApi:
path: /verify-mfa
method: post
role: VerifyMfaLambdaRole
authorizer:
handler: auth/jwt-authorizer.handler
getPresignedURLForUpload:
handler: getPresignedURLForUpload/index.handler
events:
- httpApi:
path: /files/get-upload-url
method: post
authorizer:
type: request
name: authorizer
role: GetPresignedURLForUploadLambdaRole
getListOfUserFiles:
handler: getFilesForUser/index.handler
events:
- httpApi:
path: /files/list
method: get
authorizer:
type: request
name: authorizer
role: GetListOfUserFilesLambdaRole
getPresignedURLForDownload:
handler: getPresignedURLForDownload/index.handler
events:
- httpApi:
path: /files/get-download-url/{fileName}
method: get
authorizer:
type: request
name: authorizer
role: GetPresignedURLForDownloadLambdaRole
processInvoiceS3:
handler: invoiceProcessor/index.handler
events:
- s3:
bucket: ${param:s3UploadBucketName}-${self:provider.stage}
event: s3:ObjectCreated:*
role: ProcessInvoiceLambdaRole
resources:
Resources:
UsersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Users-${self:provider.stage}
AttributeDefinitions:
- AttributeName: email
AttributeType: S
KeySchema:
- AttributeName: email
KeyType: HASH
BillingMode: PAY_PER_REQUEST
TimeToLiveSpecification:
AttributeName: ttl
Enabled: false
MfaCodesTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: MfaCodes-${self:provider.stage}
AttributeDefinitions:
- AttributeName: email
AttributeType: S
KeySchema:
- AttributeName: email
KeyType: HASH
BillingMode: PAY_PER_REQUEST
TimeToLiveSpecification:
AttributeName: ttl
Enabled: true
SignupLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: zero-trust-confidential-files-api-signup-lambda-role-${self:provider.stage}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: SignupLambdaPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- dynamodb:PutItem
Resource:
- arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/Users-${self:provider.stage}
SigninLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: zero-trust-confidential-files-api-signin-lambda-role-${self:provider.stage}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: SigninLambdaPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- dynamodb:GetItem
Resource:
- arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/Users-${self:provider.stage}
- Effect: Allow
Action:
- dynamodb:PutItem
Resource:
- arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/MfaCodes-${self:provider.stage}
VerifyMfaLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: zero-trust-confidential-files-api-verify-mfa-lambda-role-${self:provider.stage}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: VerifyMfaLambdaPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- dynamodb:GetItem
- dynamodb:DeleteItem
Resource:
- arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/MfaCodes-${self:provider.stage}
GetPresignedURLForUploadLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: get-presigned-url-for-upload-lambda-role-${self:provider.stage}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: GetPresignedURLLambdaPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:PutObject
Resource:
- arn:aws:s3:::${param:s3UploadBucketName}-${self:provider.stage}/*
GetListOfUserFilesLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: get-list-of-user-files-lambda-role-${self:provider.stage}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: GetPresignedURLLambdaPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:ListBucket
Resource:
- arn:aws:s3:::${param:s3UploadBucketName}-${self:provider.stage}
GetPresignedURLForDownloadLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: get-presigned-url-for-download-lambda-role-${self:provider.stage}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: GetPresignedURLLambdaPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:ListBucket
Resource:
- arn:aws:s3:::${param:s3UploadBucketName}-${self:provider.stage}
- Effect: Allow
Action:
- s3:GetObject
- s3:HeadObject
Resource:
- arn:aws:s3:::${param:s3UploadBucketName}-${self:provider.stage}/*
InvoicesTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Invoices-${self:provider.stage}
AttributeDefinitions:
- AttributeName: invoiceId
AttributeType: S
- AttributeName: date
AttributeType: S
KeySchema:
- AttributeName: invoiceId
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: DateIndex
KeySchema:
- AttributeName: date
KeyType: HASH
Projection:
ProjectionType: ALL
BillingMode: PAY_PER_REQUEST
ProcessInvoiceLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: ProcessInvoiceLambdaRole-${self:provider.stage}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: ProcessInvoiceLambdaPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:ListBucket
Resource:
- arn:aws:s3:::${param:s3UploadBucketName}-${self:provider.stage}
- Effect: Allow
Action:
- s3:GetObject
Resource:
- arn:aws:s3:::${param:s3UploadBucketName}-${self:provider.stage}/*
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:UpdateItem
Resource:
- arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/Invoices-${self:provider.stage}
- arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/Invoices-${self:provider.stage}/index/*
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- arn:aws:logs:${aws:region}:${aws:accountId}:log-group:/aws/lambda/zero-trust-confidential-files-api-${self:provider.stage}-processInvoiceS3:*:*
package:
exclude:
- .gitignore
- .git/**
- __tests__/**