This is a basic AWS CDK template for creating a simple Slack slash command backend.
The app in this template will display a modal window containing a text box. When submitted, the contents of the text box will be displayed within the Slack channel as an ephemeral message.
- Create a Slack slash command. The
Request Url
will be created through CDK (you will have to edit the request url in the slash command UI manually, later). This template also makes use of Interactivity (a modal window), which you can enable and set to the same url, later. - Set environment variables like those found in
.envrc_template
. Notably,SLACK_BEARER_TOKEN
corresponds to theBot User OAuth Token
found in the app UI, once installed to your Slack workspace. - Synth (
cdk synth
) and deploy (cdk deploy
) the CDK stack within this repo, which creates an API Gateway, and two Lambda Functions. There is a high probability you will also have to add several permissions to the IAM Role(s). - Once the stack has been created, edit the slash command request url and interactivity request url to match the created API Gateway endpoint.
To manually create a virtualenv on MacOS and Linux:
$ python3 -m venv .venv
After the init process completes and the virtualenv is created, you can use the following step to activate your virtualenv.
$ source .venv/bin/activate
If you are a Windows platform, you would activate the virtualenv like this:
% .venv\Scripts\activate.bat
Once the virtualenv is activated, you can install the required dependencies.
$ pip install -r requirements.txt
At this point you can now synthesize the CloudFormation template for this code.
$ cdk synth
To add additional dependencies, for example other CDK libraries, just add
them to your setup.py
file and rerun the pip install -r requirements.txt
command.
cdk ls
list all stacks in the appcdk synth
emits the synthesized CloudFormation templatecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk docs
open CDK documentation
Enjoy!