AWS Lambda
@discord0/adapter-aws deploys your app as an AWS Lambda function with a
Function URL,
using Serverless Framework v3.
Version 3 deploys with only your AWS credentials. Version 4 requires a
Serverless account or license key.
npx discord0 init my-bot --adapter awsWhat deploy generates
Section titled “What deploy generates”.discord0/aws contains index.mjs, a package.json, and a
serverless.json that creates:
- a Node.js 22 function on
arm64with 256 MB of memory and a 60-second timeout, and - a Function URL with
RESPONSE_STREAMinvoke mode.
Serverless uses your AWS CLI credentials.
Deploys go to the dev stage unless you pass --prod, which deploys the
prod stage.
Your endpoint is the Function URL followed by /interactions, which deploy
prints. npx serverless@3 info in .discord0/aws shows it again.
Credentials
Section titled “Credentials”The function reads DISCORD_PUBLIC_KEY and DISCORD_BOT_TOKEN from SSM
Parameter Store under /<name>/, where <name> is your package.json name in
lowercase, with each run of other characters replaced by a hyphen. For
example, @acme/my-bot becomes acme-my-bot. serverless.json shows the
exact paths. Serverless resolves them at deploy time, so create them before
the first deploy:
aws ssm put-parameter --name /my-bot/DISCORD_PUBLIC_KEY --type String --value <public key>aws ssm put-parameter --name /my-bot/DISCORD_BOT_TOKEN --type SecureString --value <bot token>Deferred work
Section titled “Deferred work”Lambda has no waitUntil. Instead, the adapter uses
response streaming:
it streams the response to Discord, ends the stream, and then waits for every
pending promise before the handler returns.
When you leave autoDeferAfterMs unset, the adapter defaults it to 1000ms.
Cold starts often take 0.7 to 1.5 seconds before the handler runs, and the
lower default still fits the acknowledgement inside Discord’s 3-second
window. Set autoDeferAfterMs on new Discord() to
override. See Deferred work.
- The function timeout. The invocation lasts until all deferred work settles, so the work must finish within the function timeout: 60 seconds in the generated config. Lambda allows timeouts up to 1,800 seconds. (Timeout)
deployrewritesserverless.jsoneach time, so a timeout you change in the console or with the AWS CLI resets to 60 seconds on the next deploy.- You’re billed for the full duration, including deferred work.
- Function URLs don’t support response streaming inside a VPC, so the function can’t be attached to one.
Scheduled tasks
Section titled “Scheduled tasks”With scheduled tasks, serverless.json adds a
tasks function with a 300-second timeout and an EventBridge Scheduler
schedule for each task, in the task’s time zone. Deploy converts each
expression to EventBridge’s six-field form. EventBridge can’t combine a day of
the month with a day of the week, so deploy rejects an expression that sets
both. Split it into two tasks. Scheduler bills per invocation.