-
Notifications
You must be signed in to change notification settings - Fork 6
/
template.yaml
68 lines (61 loc) · 2.36 KB
/
template.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
serverless-discord-bot
A Serverless Discord Bot template built with Discord Slash Commands and AWS SAM.
Globals:
Function:
Runtime: nodejs14.x
Timeout: 3
Resources:
CommandsLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: ./src/commands_layer
CreateCommandsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/create_commands
Description: "Function to create Discord Slash Commands"
Handler: index.lambdaHandler
Environment:
Variables:
DISCORD_APP_ID: '{{resolve:secretsmanager:/dev/serverless_discord_bot/discord:SecretString:app_id}}'
DISCORD_PUBLIC_KEY: '{{resolve:secretsmanager:/dev/serverless_discord_bot/discord:SecretString:public_key}}'
DISCORD_BOT_TOKEN: '{{resolve:secretsmanager:/dev/serverless_discord_bot/discord:SecretString:bot_token}}'
Layers:
- !Ref CommandsLayer
CreateCommandsInvoker:
Type: Custom::CreateCommandsInvoker
Properties:
ServiceToken: !GetAtt CreateCommandsFunction.Arn
# Passing the CommandsLayer ARN will cause a custom resource update every time the commands are updated.
# (note that the ARN of a LayerVersion Resource ends with an incrementing layer version number)
CommandsLayerVersion: !Ref CommandsLayer
DiscordInteractionApi:
Type: AWS::Serverless::HttpApi
Properties:
StageName: prod
DiscordHandlerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/handler
Description: "Serverless Function to handle incoming Discord requests"
Handler: index.lambdaHandler
Events:
HelloWorld:
Type: HttpApi
Properties:
ApiId: !Ref DiscordInteractionApi
Method: post
Path: /event
Environment:
Variables:
DISCORD_APP_ID: '{{resolve:secretsmanager:/dev/serverless_discord_bot/discord:SecretString:app_id}}'
DISCORD_PUBLIC_KEY: '{{resolve:secretsmanager:/dev/serverless_discord_bot/discord:SecretString:public_key}}'
Layers:
- !Ref CommandsLayer
Outputs:
DiscordInteractionApi:
Description: "API Gateway endpoint URL"
Value: !Sub "https://${DiscordInteractionApi}.execute-api.${AWS::Region}.amazonaws.com/prod/event"