How to — AWS Lambda and Slack App

Vladimir Pasquier
Aug 22, 2017 · 2 min read

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 (/location command) is sending a POST.
  • The API Gateway is transforming the Form body into JSON (see Velocity script aws-template-api-gateway in 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!).

)

Vladimir Pasquier

Written by

@nuxeo Software Engineer | Currently Based in New York, USA | Speaking English, Spanish and French

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade