A bit of coding, a byte of the cloud. Learning to code a cheap and cheerful alerting tool in an AWS Lambda function.

Code can do it. You can code. Do it.

Years ago I learned on the job to write little PERL programs and Shell scripts to manipulate data in files submitted by clients who could not deliver their transaction data conformed to a record layout that my employer’s application could ingest. Did I lose you already? I chopped up some stuff to make it work. That’s what I love about code, it can do anything to anything for anything that needs doing with data.

At Tesloop, needs are much more realtime. When one of our vehicles arrives at a location where it is scheduled to pick up or drop off passengers, it’s that moment and the minutes that follow when the driver (pilot) or passenger may need help from the Operations team. Our developers created an SNS topic on AWS that our serverless application (using Kinesis Analytics) posts to when a vehicle enters a custom geofence that we have defined around each location. To give the team a heads up, a Slack post is best. Our driver mobile app also posts to Slack when arriving at locations, but redundancy is good and triggering based on the vehicle data creates some additional benefits. All we needed was a way to make a Slack post for each post to the SNS topic.

Inspired by a post on Medium by Joseph Terranova it seemed trivial to extend his code to extract a vehicle ID number from the data and construct a link to our fleet monitoring dashboard. I did this as a proof of concept, to be improved upon or completely re-architected by our developers later. The immediate goal was simply to alert the Ops team.

Below is the code you can copy-paste into your Lambda function after following Joseph’s instructions for creating your Slack webhook and SNS topic. Don’t forget to replace the values for:

  1. Slack webhook path (line 1)
  2. Slack channel (line 2)
  3. Slack posting username (line 3)
  4. Switch values (line 10-18)
  5. Message template (line 28)

The result for me was nice little notification posts like the one shown below. Done. Did it.

Slack say what?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s