Discord Serverless Bot with Lambda Proxy is an example SAM application (template or framework), that uses AWS Services - AWS API Gateway with Proxy AWS Lambda Function, in order to split functions based on event's request body.
Discord application sends all events to one endpoint URL. Our architecture prevents Discord Serverless Bot from becoming a Lambda Monolith.
Prerequisites:
- AWS SAM CLI
- AWS User connected to CLI
- Discord Application created and invited to your test guild
- Node.js
Clone this repo with AWS SAM
mkdir my-serverless-discord-bot && \
cd my-serverless-discord-bot && \
sam init --location gh:jakjus/serverless-discord-bot
Install required packages
npm install
We are templating the main template.yaml
file with generate_template/generate.js
, so it's not in the main folder by default.
- Get your development Guild (Discord Server) Id by enabling Developer Mode in settings and right-clicking your guild.
- Get App Id and Bot Token from Discord Developers Portal.
- Copy
.env.example
to.env
and fill.env
with real values.
Generate template based on your folder structure and metadata in src/
:
node generate_template/generate.js
Register commands on one guild for development (instant):
node register_commands/register.js
If you will not specify GUILD_ID
environment variable, deployed commands will be global.
Build and deploy with:
sam build && sam deploy --guided
- Create a new command in
src/modules/example/another-one.js
similar tohello-from-lambda.js
. It must have another name within theexports.data
. - Generate template, register commands, build and deploy using:
node generate_template/generate.js && \
node register_commands/register.js && \
sam build && sam deploy
sam delete
This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) command line interface (CLI). It includes the following files and folders:
src
- Code for the application's Lambda function.events
- Invocation events that you can use to invoke the function.__tests__
- Unit tests for the application code.template.yaml
- A template that defines the application's AWS resources.
Resources for this project are defined in the template.yaml
file in this project. The file has its own template generator. You can update the template to add AWS resources through the same deployment process that updates your application code.
If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit.
The AWS Toolkit is an open-source plugin for popular IDEs that uses the AWS SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds step-through debugging for Lambda function code.
To get started, see the following:
For an introduction to the AWS SAM specification, the AWS SAM CLI, and serverless application concepts, see the AWS SAM Developer Guide.
Next, you can use the AWS Serverless Application Repository to deploy ready-to-use apps that go beyond Hello World samples and learn how authors developed their applications. For more information, see the AWS Serverless Application Repository main page and the AWS Serverless Application Repository Developer Guide.