This repository contains a simple Discord bot implemented in Rust for AWS Lambda. It is set up to respond to the /ask
command.
The execution environment is assumed to be provided.al2 (Amazon Linux 2)/arm64. Therefore, the default build target is aarch64-unknown-linux-musl
.
If you are building on macOS, use FiloSottile/homebrew-musl-cross or emk/rust-musl-builder.
The discord
crate can be built using the following command:
cargo build --release
Please follow the steps in the official documentation's Getting Started guide for deployment procedures.
AWS Lambda needs to refer to the raw http body for signature verification, so you need to have Proxy Integration enabled.
The following tokens are required for execution. For more details, please see Adding Credentials.
DISCORD_PUBLIC_KEY
DISCORD_TOKEN
After deployment, register the slash command. For more details, please see Installing slash commands.
cd discord_register
APP_ID=*** cargo run
Configure the Execution role of Lambda functions as follows:
Grant the following permissions to enable access to the related services:
- AWSLambdaBasicExecutionRole
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}