-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
519 lines (479 loc) · 14.3 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
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
service: chzzk
useDotenv: true
provider:
name: aws
runtime: python3.10
region: ap-northeast-2
profile: chzzk
logRetentionInDays: 7
architecture: x86_64
memorySize: 128
timeout: 10
versionFunctions: false
stage: prodV2
environment:
DISCORD_PUBLIC_KEY: ${env:DISCORD_PUBLIC_KEY}
DISCORD_TOKEN: ${env:DISCORD_TOKEN}
DISCORD_CLIENT_ID: ${env:DISCORD_CLIENT_ID}
DISCORD_CLIENT_SECRET: ${env:DISCORD_CLIENT_SECRET}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:*
Resource: "arn:aws:dynamodb:*:*:*"
- Effect: Allow
Action:
- kms:Decrypt
Resource: arn:aws:kms:*:*:*
functions:
event_handler:
handler: lambdas/event_handler.handler
name: event_handler_v2
description: Handle event from discord (slash command, interaction)
events:
- http:
path: event
method: post
cors: true
layers:
- arn:aws:lambda:ap-northeast-2:897699718511:layer:pynacl_layer:111
live_check:
handler: lambdas/live_check.handler
name: live_check_v2
description: live check V2
timeout: 270
naver_session_renew:
handler: lambdas/naver_session_renew.handler
name: naver_session_renew_v2
description: 네이버 계정 세션 갱신
timeout: 60
events:
- schedule: rate(12 hours)
discord_oauth2_redirect:
handler: lambdas/discord_oauth2_redirect.handler
name: discord_oauth2_redirect_v2
description: Handle OAuth2 redirect from discord
events:
- http:
path: oauth/token
method: post
cors: true
discord_me:
handler: lambdas/discord_me.handler
name: discord_me_v2
description: Get user information from discord
events:
- http:
path: discord/me
method: get
cors: true
discord_guilds:
handler: lambdas/discord_guilds.handler
name: discord_guilds_v2
description: Get guilds information from discord
events:
- http:
path: discord/guilds
method: get
cors: true
get_guild_channels:
handler: lambdas/get_guild_channels.handler
name: get_guild_channels_v2
description: 특정 ID의 디스코드 서버의 채널 목록을 가져옵니다. 만약 해당 서버가 존재하지 않거나 접근할 수 없는 경우 404를 반환합니다.
events:
- http:
path: discord/{guild_id}/channels
method: get
cors: true
post_notification:
handler: lambdas/post_notification.handler
name: post_notification_v2
description: 치지직 알림을 추가합니다.
events:
- http:
path: notifications
method: post
cors: true
get_notification_by_guild_id:
handler: lambdas/get_notification_by_guild_id.handler
name: get_notification_by_guild_id_v2
description: 특정 ID의 디스코드 서버의 알림 목록을 가져옵니다. 데이터가 없을 경우 빈 리스트를 반환합니다.
events:
- http:
path: notifications/{guild_id}
method: get
cors: true
delete_notification:
handler: lambdas/delete_notification.handler
name: delete_notification_v2
description: 알림을 삭제합니다. 만약 해당 알림이 없으면 404를 반환합니다.
events:
- http:
path: notifications
method: delete
cors: true
send_test_notification:
handler: lambdas/send_test_notification.handler
name: send_test_notification_v2
description: 테스트 알림을 보냅니다.
events:
- http:
path: notifications/test
method: post
cors: true
update_notification:
handler: lambdas/update_notification.handler
name: update_notification_v2
description: 알림을 수정합니다. 만약 해당 알림이 없으면 404를 반환합니다.
events:
- http:
path: notifications
method: put
cors: true
package:
include:
- "lambdas/**"
- "shared/**"
- "requirements.txt"
exclude:
- "node_modules/**"
- "venv/**"
- ".git/**"
- ".github/**"
- "terraform/**"
- "frontend/**"
- "serverless.yml"
- ".serverless/**"
- "etc/**"
resources:
Resources:
ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: Chzzk-API
Description: API for chzzk.junah.dev
ApiGatewayCustomDomain:
Type: AWS::ApiGateway::DomainName
Properties:
DomainName: api.chzzk.junah.dev
RegionalCertificateArn: arn:aws:acm:ap-northeast-2:897699718511:certificate/86908885-faea-49f8-bed6-299f402ff4d4
EndpointConfiguration:
Types:
- REGIONAL
SecurityPolicy: TLS_1_2
ApiGatewayBasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
Properties:
DomainName:
Ref: ApiGatewayCustomDomain
RestApiId:
Ref: ApiGatewayRestApi
Stage: prodV2
ApiGatewayInviteResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- ApiGatewayRestApi
- RootResourceId
PathPart: invite
RestApiId:
Ref: ApiGatewayRestApi
ApiGatewayInviteMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
Type: HTTP_PROXY
IntegrationHttpMethod: GET
Uri: "https://discord.com/api/oauth2/authorize?client_id=1191657232480350238&permissions=137439398912&scope=bot"
ResourceId:
Ref: ApiGatewayInviteResource
RestApiId:
Ref: ApiGatewayRestApi
# ApiGatewayInviteAdminResource:
# Type: AWS::ApiGateway::Resource
# Properties:
# ParentId:
# Fn::GetAtt:
# - ApiGatewayInviteResource
# - arn
# PathPart: admin
# RestApiId:
# Ref: ApiGatewayRestApi
# ApiGatewayInviteAdminMethod:
# Type: AWS::ApiGateway::Method
# Properties:
# AuthorizationType: NONE
# HttpMethod: GET
# Integration:
# Type: HTTP_PROXY
# IntegrationHttpMethod: GET
# Uri: "https://discord.com/api/oauth2/authorize?client_id=1191657232480350238&permissions=8&scope=bot"
# ResourceId:
# Ref: ApiGatewayInviteAdminResource
# RestApiId:
# Ref: ApiGatewayRestApi
ApiGatewaySupportServerResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- ApiGatewayRestApi
- RootResourceId
PathPart: support-server
RestApiId:
Ref: ApiGatewayRestApi
ApiGatewaySupportServerMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
Type: HTTP_PROXY
IntegrationHttpMethod: GET
Uri: "https://discord.gg/jUuCxtyySK"
ResourceId:
Ref: ApiGatewaySupportServerResource
RestApiId:
Ref: ApiGatewayRestApi
LiveCheckTriggerFor0:
Type: AWS::Events::Rule
Properties:
Name: live_check_trigger_for_0
Description: Live check trigger for index 0
ScheduleExpression: cron(0/5 * ? * * *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- LiveUnderscorecheckLambdaFunction
- Arn
Id: live_check_trigger_for_0
PermissionForEventsToInvokeLambda0:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: LiveUnderscorecheckLambdaFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn:
Fn::GetAtt:
- LiveCheckTriggerFor0
- Arn
LiveCheckTriggerFor1:
Type: AWS::Events::Rule
Properties:
Name: live_check_trigger_for_1
Description: Live check trigger for index 1
ScheduleExpression: cron(1/5 * ? * * *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- LiveUnderscorecheckLambdaFunction
- Arn
Id: live_check_trigger_for_1
PermissionForEventsToInvokeLambda1:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: LiveUnderscorecheckLambdaFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn:
Fn::GetAtt:
- LiveCheckTriggerFor1
- Arn
LiveCheckTriggerFor2:
Type: AWS::Events::Rule
Properties:
Name: live_check_trigger_for_2
Description: Live check trigger for index 2
ScheduleExpression: cron(2/5 * ? * * *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- LiveUnderscorecheckLambdaFunction
- Arn
Id: live_check_trigger_for_2
PermissionForEventsToInvokeLambda2:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: LiveUnderscorecheckLambdaFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn:
Fn::GetAtt:
- LiveCheckTriggerFor2
- Arn
LiveCheckTriggerFor3:
Type: AWS::Events::Rule
Properties:
Name: live_check_trigger_for_3
Description: Live check trigger for index 3
ScheduleExpression: cron(3/5 * ? * * *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- LiveUnderscorecheckLambdaFunction
- Arn
Id: live_check_trigger_for_3
PermissionForEventsToInvokeLambda3:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: LiveUnderscorecheckLambdaFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn:
Fn::GetAtt:
- LiveCheckTriggerFor3
- Arn
LiveCheckTriggerFor4:
Type: AWS::Events::Rule
Properties:
Name: live_check_trigger_for_4
Description: Live check trigger for index 4
ScheduleExpression: cron(4/5 * ? * * *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- LiveUnderscorecheckLambdaFunction
- Arn
Id: live_check_trigger_for_4
PermissionForEventsToInvokeLambda4:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: LiveUnderscorecheckLambdaFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn:
Fn::GetAtt:
- LiveCheckTriggerFor4
- Arn
LiveCheckTriggerFor5:
Type: AWS::Events::Rule
Properties:
Name: live_check_trigger_for_5
Description: Live check trigger for index 5
ScheduleExpression: cron(0/5 * ? * * *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- LiveUnderscorecheckLambdaFunction
- Arn
Id: live_check_trigger_for_5
PermissionForEventsToInvokeLambda5:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: LiveUnderscorecheckLambdaFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn:
Fn::GetAtt:
- LiveCheckTriggerFor5
- Arn
LiveCheckTriggerFor6:
Type: AWS::Events::Rule
Properties:
Name: live_check_trigger_for_6
Description: Live check trigger for index 6
ScheduleExpression: cron(1/5 * ? * * *)
State: ENABLED
Targets:
- Arn:
Fn::GetAtt:
- LiveUnderscorecheckLambdaFunction
- Arn
Id: live_check_trigger_for_6
PermissionForEventsToInvokeLambda6:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Ref: LiveUnderscorecheckLambdaFunction
Action: lambda:InvokeFunction
Principal: events.amazonaws.com
SourceArn:
Fn::GetAtt:
- LiveCheckTriggerFor6
- Arn
# TODO : Import DynamoDB Table from original resources
# DynamoDBTable:
# Type: AWS::DynamoDB::Table
# Properties:
# TableName: chzzk-bot-db
# BillingMode: PAY_PER_REQUEST
# AttributeDefinitions:
# - AttributeName: PK
# AttributeType: S
# - AttributeName: SK
# AttributeType: S
# - AttributeName: guild_id
# AttributeType: S
# - AttributeName: type
# AttributeType: S
# - AttributeName: index
# AttributeType: N
# KeySchema:
# - AttributeName: PK
# KeyType: HASH
# - AttributeName: SK
# KeyType: RANGE
# GlobalSecondaryIndexes:
# - IndexName: GSI-SK
# KeySchema:
# - AttributeName: SK
# KeyType: HASH
# - AttributeName: PK
# KeyType: RANGE
# Projection:
# ProjectionType: KEYS_ONLY
# - IndexName: GSI-GuildID
# KeySchema:
# - AttributeName: guild_id
# KeyType: HASH
# - AttributeName: PK
# KeyType: RANGE
# Projection:
# ProjectionType: INCLUDE
# NonKeyAttributes:
# - SK
# - channel_id
# - channel_name
# - custom_message
# - disable_button
# - disable_embed
# - last_noti_at
# - last_noti_status
# - IndexName: GSI-type
# KeySchema:
# - AttributeName: type
# KeyType: HASH
# Projection:
# ProjectionType: INCLUDE
# NonKeyAttributes:
# - PK
# - lastLiveId
# - IndexName: GSI-index
# KeySchema:
# - AttributeName: index
# KeyType: HASH
# - AttributeName: PK
# KeyType: RANGE
# Projection:
# ProjectionType: ALL
custom:
pythonRequirements:
slim: true
plugins:
- serverless-python-requirements
- serverless-dotenv-plugin