Skip to content

[QUICKSTART] λ Deploy your bot to a "serverless" AWS Lambda Function

  • This example uses the Serverless Stack (SST) toolchain for provisioning, deployment of infrastructure and makes it possible to express your infrastructure needs as spec/code

  • SpeedyBot has been built with serverless in mind from the beginning-- serverless infrastructure is "asleep" until you need it (ie when a user sends a message, card, or file). S

  • Start-up times are generally fast enough to interact with the chat client without timing out. Check out the Worker sample for a fast-loading V8 Isolate without the overhead of a container

1) Fetch repo & install dependencies

git clone https://github.com/valgaze/speedybot
cd speedybot
cd examples/lambda
npm install

Note: The actual code of the agent located in packages/functions/src/settings/bot.ts and lamba code is available packages/functions/src/lambda.ts

2) Set your bot access token

sh
WEBHOOK_SECRET=__REPLACE__ME__
BOT_TOKEN=__REPLACE__ME__

Note: WEBHOOK_SECRET is up to you, incoming requests will be hashed with it, if the hash is present on the incoming request & WEBHOOK_SECRET is present, the lambda will attempt to validate the request. If it fails to match the request will be rejected

Note: The .env file musts never be aded to source control (and there are may ways to supply sensitive data to lambda functions with SST)

3) Set up your AWS credentials on your machine

Note: You'll need an AWS account that has authorization/billing to create lambda functions

3a. Setup IAM here: https://sst.dev/chapters/create-an-iam-user.html

3b. Setup AWS CLI: https://sst.dev/chapters/configure-the-aws-cli.html

4) Deploy your bot and obtain its public URL

Run this command from the project directory:

npm run deploy

If deployment is successful, you should find that your url that looks something like this: https://abcd123456.execute-api.us-east-1.amazonaws.com

5) Register your webhooks

Note: This uses SST but any deployment mechanism/structure you prefer works fine

Note: This SST configuration is setup to capture incoming WebEx requests on the /speedybot route, you can change any/all the behavior in the stack config

6) Take it for a spin

  • After connecting webhooks, take it for a spin

7) Local Dev

SST has a cool feature where you can develop your lambda/bot code locally but reach real AWS services.

Install dependencies in packages/functions/src and run npm install and you can run the following command for live-reload:

npm run dev