How to — AWS Lambda and Slack App
The example

Slack Location is a tool to quickly view Slack team members sorted by location (depending on their status icon or text). Looking for the timezone is not implemented because you need for each user to call this and this tool has no tracking purpose :)
It is just an example of a Serverless Slack Command Integration using AWS Lambda and AWS API Gateway.
The big picture
Flow

- The Slack client (
/locationcommand) is sending a POST. - The API Gateway is transforming the Form body into JSON (see Velocity script
aws-template-api-gatewayin the tree below). - The Lambda is taking the hand and calling the Slack API for fetching the Slack team members information (via OAuth).
- Slack is returing the information post-filtered by the Lambda which is returning a proper JSON response for the Slack client.
App Structure
.
├── LICENSE
├── README.md
├── aws (script aws for pushing/invoking aws lambdas)
│ ├── awsCreate.sh
│ ├── awsInvoke.sh
│ ├── awsUpdate.sh
├── aws-template-api-gateway (script for API Gateway transformation)
├── build.sh (zip all project into ./dist/lambda.zip)
├── config.json (slack tokens)
├── dist
│ └── lambda.zip
├── index.js (Lambda script)
├── package.json
├── spec
│ ├── lambda.spec.js (Jasmin test)Don’t hesitate to check out this repository. You will be able to deploy your lambda easily and having an example of how to use the Slack command POST body and returning the proper response.
The result

Follow the Readme here to know how to configure and install the app (it’s not distributed inside the Slack marketplace).
Pitfalls
Amazon API Gateway was actually the most tricky part. If you have any issue like this one, don’t hesitate to debug your Velocity template (check in all cases your API Gateway and Lambda CloudWatch!).