AWS Slack Slash Command CDK Template
Fri 11 September 2020On the face of it, making a Slack slash command sounds relatively straight forward:
- set up a slash command through the Slack UI that points to an endpoint
- when the slash command is executed, Slack sends a POST request to the endpoint
- the code within the endpoint then hopefully does something, and possibly returns a result of some kind to Slack
In practice, there are many subtleties inherent in making a functional Slack slash command app, which (hopefully) you will find managed by this AWS CDK template.
This template does a few things for you:
- creates an API Gateway, set up for cross-domain POST requests
- creates a
main
lambda function, which invokes theworker
lambda function, but also always immediately returns a successful 200 response to Slack - creates a
worker
lambda function, which executes the business logic of the slash command. When the slash command is first invoked, this lambda displays a modal window. When the modal is submitted, this lambda is invoked again to create and return an ephemeral Slack message to the channel, containing the text contents of the modal window.
Hopefully you find this CDK template useful. I'll be interested to hear if you make use of it!