
This guide walks you through the simple process of building a cool custom Slack app (slash command). From writing the code in Python on AWS Lambda to making it API exposed, and finally enabling in your Slack Channel. It is all very easy if you follow the guide.
1. Build your AWS Lambda Function

Making a lambda function is extremely easy. To integrate with Slack, make an AWS Lambda function that reads the command args and returns JSON. The KEY is:
- Input comes in Base64 Encoded AND URL encoded
- Output needs to be in JSON with a very specific format
Code (in this case, a simple isPrime() function):
That’s more code than you really need, but here are the key takeaways:
- Extract the base64 nvpair encodings to a map.
- Get the command + params from the map.
- Callback to the commands map (dict of subcommands -> functions).
- Wrap the response in a Slack defined JSON.
Note that testing within AWS requires you to put the inputs in Slack format — base64 + nvpair urlencoded. Your test input should look like the image below for an input string like “command=%2Ffoo&text=bar+3”. (Pro tip use: https://www.base64encode.net/)

Test output below (triggers expected error):

2. Make your AWS Lambda a Service
Enabling the AWS Lambda as a web callable service is next. Note the endpoint URL after creating it (something like https://xxx.execute-api.ap-northeast-1.amazonaws.com/default/MySlackFunc). Note this OPEN security means someone hit your Lambda service 10b times and has run up your bill so be careful (this is why I haven’t published my real URL)!

3. Register your app on Slack
Go to https://api.slack.com and start building a new API. Choose a name and Slack workspace (assuming you are logged into Slack in the browser).

Then choose “Slash commands” and fill out the content fields using the HTTP URL from the Lambda API.

The final step within the Slack API site is to install it or make it public in the store (again, it may cost you AWS funds if it’s a smash hit):

4. Test and enjoy!
Test drive it in your Slack Channel:

You can add more subcommands to the Lambda code quite easily! Have fun.
Happy slacking!