This repo provides the source code for building a Slack Command App/Bot with AWS API Gateway and Lambda Functions. This SlackApp can handle requests triggered from a Slash Command which will take longer than 3 seconds to process, and posts the details back to the user.
To create a Slack Command in Slack (the default command in this repo is /lookup
)
- Navigate to https://api.slack.com/apps.
- Select Create New App and select Slash Commands.
- Enter the name
/lookup
for the command and click Add Slash Command Integration. - Enter the provided API endpoint URL in the URL field.
- Copy the Verification Token from Basic Information.
- Deploy a CloudFormation stack with cloudformation/S3-Artifacts-template.yaml, that creates a S3 bucket for stroing the Lambda Function artifacts.
- Package and upload the Lambda Function artifacts to S3 with scripts/upload_artifacts_to_s3.sh.
- Store your Slack token in Parameter Store with scripts/create_ssm_parameter.py.
- Deploy a CloudFormation stack with cloudformation/SlackCommandApp-template.yaml, that creates the following AWS Components.
- An API Gateway to provide an endpoint to be invoked from a Slack Command.
- A Lambda Function lambda/slack_app_immediate_response.py to perform authentication, some basic checks and send an intermediate response to Slack within 3 seconds (Slack requirement). This function invokes another Lambda function to to the request tasks (synchronously invocation for quick task; asynchronous invocation for long tasks).
- A Lambda Function lambda/slack_app_async_worker.py to perform actual operation that may take more than 3 seconds to finish.
- A Lambda Function lambda/slack_app_sync_worker.py to perform actual operation that takes less than 3 seconds to finish.
- A KMS key for encryption in transit for Slack token.
- A S3 bucket for storing logs.
E.g. if command is /lookup
, then
- Run
/lookup async
- Run
/lookup sync