Creating a simple Slackbot in AWS Lambda

It doesn’t take many lines to do something cool with Slack and AWS Lambda.

Simply put, you can generate an incoming webhook into Slack very easily (their documentation is straight forwards)

In fact, they even end up giving you a curl command to test posting to slack.

This should tell you something.

It’s just an HTTP call.

And you can easily do that from AWS Lambda.

I’m trying to decide whether to share code, but to be honest, it’s relatively simple to do in pseudo code.

Pseudo code is:

  1. Get the data you want to use (could pass in as an event)
  2. Create the JSON payload
  3. Send the payload via HTTPS to the details given by slack (the https module is included in node of course)
  4. that’s it!

It can be done in a curl command as well, which means it’s simple.

It can be done in around 30 lines (50 lines is more readable with comments though)

We use it for reporting.

Simple, basic reporting.

We don’t have a reporting website.

We just report into a slack channel, and retrieve data if we need it based upon that information.

We implement from a DynamoDB Trigger.

On a Dynamo change (Insert, Update) you can trigger a Lambda function to run. Every time we receive a specific piece of data into the table, we run the function, and send that data into Slack.

You could do this with error reporting, support queries, high revenue moments…

We have found it’s really nice to know that our app is adding value to our users and are adapting the data we receive based upon that information.

And because you can provide buttons as part of the payload, you can provide opportunities to download the data you’ve just sent them.

I know this sounds odd, but I am all about simplicity and keeping down maintenance.

Maintaining a single slackbot and providing certain data from it to Slack with the ability to download the data from S3 (or however it’s done) if needs be, is remarkably simple.

Written by

ServerlessDays CoFounder (Jeff), ex AWS Serverless Snr DA, experienced CTO/Interim, Startups, Entrepreneur, Techie, Geek and Christian

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store