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)

var services = '/services/…'; // Update this with your Slack webhook URL path
var channel = '#fleet-status'; // Update this with the Slack channel to post in
var username = 'Vehicle GeoFence Alert'; //Update this with the Slack username to show on the posts
var https = require('https');
var util = require('util');
function vehicleName(vehicleId) {
switch (vehicleId) {
case 9999991:return "Rex";
case 9999992:return "Toro";
case 9999993:return "Ruby";
case 9999994:return "Wally";
case 9999995:return "Deuxy";
case 9999996:return "Bravo";
case 9999997:return "Duke";
case 9999998:return "eHawk";
default:"Mystery Mobile"
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
var vehicleId = event.vehicle_id;
var message = vehicleName(vehicleId) + ' is arriving at a stop! See it on the fleet dashboard: https://fleet.tesloop.com/dashboard/vehicles/' + vehicleId;
var postData = {
"channel": channel,
"username": username,
"text": message,
"icon_emoji": ":round_pushpin:"
var options = {
method: 'POST',
hostname: 'hooks.slack.com',
port: 443,
path: 'services'
var req = https.request(options, function(res) {
res.on('data', function (chunk) {
req.on('error', function(err) {
console.log('Houston, we have a problem: ' + err.message);
req.write(util.format("%j", postData));

view raw


hosted with ❤ by GitHub

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

Slack say what?

Oh no, I broke my nerdboard. How DIY electronics skills and open source software saved the day, and my hands.

My hands were hurting. I work in software development, spending many hours each day typing, and I also play bass guitar in two bands (one coincidentally named Static Hands). The toll this took on my hands became so great that I was experiencing muscle spasms that immobilized my right thumb. Ouch.

At the greatly appreciated suggestion of a coworker, I looked at the Kinesis Advantage ergonomic keyboard. The reviews promised it would be like typing on clouds, but the price is steep at $350. I found one used for $150, a bargain, but this one had a defect. The tilde key was sticking, not the key cap as happens from a spilled soda, but inside the switch underneath. Uh oh.

DIY electronics skills to the rescue! I opened the keyboard and desoldered the offending key from the cool, curved circuit board that reminded of samurai armor.

The Kinesis Advantage “Nerdboard” comes with space for your favorite action figure.

Inside we see the curved circuit boards that the keys are soldered on to.

The desoldered key’s now empty circuit board contacts.

With the sticking key gone I still needed to re-map the tilde key, because I use the back tick character (which also lives on that key) for quoting code in Slack. An open source, free application called Karabiner did the job with ease, after a few puzzled minutes figuring out its quirky user interface.

Should you ever need key re-mapping, please support the creator of Karabiner with a $10 donation. Many open source software projects survive on donations alone, and they are worthy of our support. In the realm of audio, there is the venerable Audacity, which has saved me on more than one occasion when expensive audio editing applications broke down… but that’s for another post.