-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
344 lines (328 loc) · 9.32 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
service: tms
frameworkVersion: "3"
package:
# individually: true
excludeDevDependencies: true
exclude:
- src/**
- .jest/**
- scripts/**
- .eslintrc.yaml
- .gitignore
- jest.config.ts
- makefile
- readme.md
- tsconfig.json
- yarn.lock
plugins:
- serverless-deployment-bucket
- serverless-dotenv-plugin
useDotenv: true
provider:
name: aws
runtime: nodejs20.x
deploymentMethod: direct
stage: ${opt:stage, 'dev'}
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:* # allows all dynamodb actions
Resource:
- Fn::GetAtt: [TMSSystemTable, Arn]
- Fn::Join:
- "/"
- - Fn::GetAtt: [TMSSystemTable, Arn]
- "index/*"
- Fn::GetAtt: [websocketTable, Arn]
- Effect: Allow
Action:
- sns:Publish
Resource:
- Ref: TaskChangedNotificationTopic
environment:
stage: ${opt:stage, self:provider.stage}
httpApi:
cors: true
authorizers:
internalAuthorizer:
type: request
functionName: internal_authorizer
identitySource:
- $request.header.Authorization
enableSimpleResponses: true
payloadVersion: "2.0"
deploymentBucket:
name: ${self:service}-${self:provider.stage}-deployment-bucket
blockPublicAccess: true
resources:
Resources:
TMSSystemTable:
Type: "AWS::DynamoDB::Table"
Properties:
TableName: "TMSSystemTable"
AttributeDefinitions:
- AttributeName: "pk"
AttributeType: "S"
- AttributeName: "sk"
AttributeType: "S"
- AttributeName: "entity_type"
AttributeType: "S"
- AttributeName: "status"
AttributeType: "S"
- AttributeName: "due_date"
AttributeType: "S"
KeySchema:
- AttributeName: "pk"
KeyType: "HASH"
- AttributeName: "sk"
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
GlobalSecondaryIndexes:
- IndexName: "statusIndex"
KeySchema:
- AttributeName: "pk"
KeyType: "HASH"
- AttributeName: "status"
KeyType: "RANGE"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
- IndexName: "dueDateIndex"
KeySchema:
- AttributeName: "pk"
KeyType: "HASH"
- AttributeName: "due_date"
KeyType: "RANGE"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
- IndexName: "EntityTypeIndex"
KeySchema:
- AttributeName: "pk"
KeyType: "HASH"
- AttributeName: "entity_type"
KeyType: "RANGE"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
StreamSpecification:
StreamViewType: "NEW_IMAGE"
FileInventoryBucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: "file-inventory-bucket-self"
AccessControl: "Private"
VersioningConfiguration:
Status: "Enabled"
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
LifecycleConfiguration:
Rules:
- Id: "DeleteOldFiles"
Status: "Enabled"
ExpirationInDays: 30 # 30일 후 파일 삭제
TaskChangedNotificationTopic:
Type: "AWS::SNS::Topic"
Properties:
TopicName: "task-changed-notification-topic"
DisplayName: "TaskChangedNotificationTopic"
TaskChangedNotificationQueue:
Type: "AWS::SQS::Queue"
Properties:
QueueName: "task-changed-notification-queue"
MessageRetentionPeriod: 86400
RedrivePolicy:
deadLetterTargetArn: !GetAtt TaskChangedNotificationDLQ.Arn
maxReceiveCount: 5
TaskChangedNotificationDLQ:
Type: "AWS::SQS::Queue"
Properties:
QueueName: "task-changed-notification-dlq"
VisibilityTimeout: 300
MessageRetentionPeriod: 86400
TaskChangedNotificationSubscription:
Type: "AWS::SNS::Subscription"
Properties:
Protocol: "sqs"
TopicArn: !Ref TaskChangedNotificationTopic
Endpoint: !GetAtt TaskChangedNotificationQueue.Arn
websocketTable:
Type: "AWS::DynamoDB::Table"
Properties:
TableName: "websocketTable"
AttributeDefinitions:
- AttributeName: "connectionId"
AttributeType: "S"
- AttributeName: "user_email"
AttributeType: "S"
KeySchema:
- AttributeName: "connectionId"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
GlobalSecondaryIndexes:
- IndexName: "userEmailIndex"
KeySchema:
- AttributeName: "user_email"
KeyType: "HASH"
Projection:
ProjectionType: "ALL"
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
functions:
s3ObjectCreatedEventFunction:
handler: dist/lambda/event/s3-object-created.handler
events:
- s3:
bucket: !Ref FileInventoryBucket
event: s3:ObjectCreated:*
existing: true
v1_auth_google_authorize:
handler: dist/routes/v1/auth/google/authorize/index.handler
events:
- httpApi:
method: POST
path: /v1/auth/google/authorize
v1_auth_google_refresh:
handler: dist/routes/v1/auth/google/refresh/index.handler
events:
- httpApi:
method: POST
path: /v1/auth/google/refresh
v1_auth_google_revoke:
handler: dist/routes/v1/auth/google/revoke/index.handler
events:
- httpApi:
method: POST
path: /v1/auth/google/revoke
v1_file_list:
handler: dist/routes/v1/file/list/index.handler
events:
- httpApi:
method: GET
path: /v1/files
authorizer:
name: internalAuthorizer
v1_file_upload:
handler: dist/routes/v1/file/upload/index.handler
events:
- httpApi:
method: POST
path: /v1/files/upload
authorizer:
name: internalAuthorizer
v1_task_create:
handler: dist/routes/v1/task/create/index.handler
events:
- httpApi:
method: POST
path: /v1/tasks
authorizer:
name: internalAuthorizer
v1_task_list:
handler: dist/routes/v1/task/list/index.handler
events:
- httpApi:
method: GET
path: /v1/tasks
authorizer:
name: internalAuthorizer
v1_task_update:
handler: dist/routes/v1/task/update/index.handler
events:
- httpApi:
method: PUT
path: /v1/tasks/{task_id}
authorizer:
name: internalAuthorizer
v1_task_delete:
handler: dist/routes/v1/task/delete/index.handler
events:
- httpApi:
method: DELETE
path: /v1/tasks/{task_id}
authorizer:
name: internalAuthorizer
v1_me_get:
handler: dist/routes/v1/me/get/index.handler
events:
- httpApi:
method: GET
path: /v1/me
authorizer:
name: internalAuthorizer
internal_docs_html:
handler: dist/routes/internal/docs/html/index.handler
events:
- httpApi:
method: GET
path: /internal/docs/html
internal_docs_json:
handler: dist/routes/internal/docs/json/index.handler
events:
- httpApi:
method: GET
path: /internal/docs/json
internal_docs_yaml:
handler: dist/routes/internal/docs/yaml/index.handler
events:
- httpApi:
method: GET
path: /internal/docs/yaml
internal_health:
handler: dist/routes/internal/health/index.handler
events:
- httpApi:
method: GET
path: /internal/health
internal_authorizer:
handler: dist/lambda/authorizer/index.handler
websocket_connect:
handler: dist/lambda/websocket/index.handler
events:
- websocket:
route: $connect
websocet_disconnect:
handler: dist/lambda/websocket/index.handler
events:
- websocket:
route: $disconnect
websocket_default:
handler: dist/lambda/websocket/index.handler
events:
- websocket:
route: $default
TMSDDBRecordChangedFunction:
handler: dist/lambda/stream/ddb-record-changed.handler
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- TMSSystemTable
- StreamArn
batchSize: 1
startingPosition: LATEST
TaskChangedNotificationFunction:
handler: dist/lambda/queue/task-noti-consume.handler
events:
- sqs:
arn:
Fn::GetAtt:
- TaskChangedNotificationQueue
- Arn