Code can do it. You can code. Do it.
As a co-founder and leader at Tesloop I was constantly finding ways that code could solve problems. Tesloop provided a new kind of shared-ride transportation service in Tesla cars. The shared ride model and the electric cars both presented unique challenges.
One challenge was coordinating between drivers and passengers to meet for pick up. Tesloop picked up passengers at public locations to keep the ride moving for other passengers already in the vehicle. When a driver arrived, we automatically sent the passenger a text message update. Passengers often needed a little help finding the driver. We needed to know when to be ready to help.
The Tesloop engineers had already created a solution that texted the passenger. When the vehicle location data told us the vehicle was at the location our code created a message on Amazon Simple Notification Service (SNS). The Tesloop operations team needed their own alerts to monitor the entire fleet of vehicles. The best place to get those alerts was in a Slack channel. I wanted to find a solution with the least amount of code to turn those SNS messages into Slack posts.
Reducing our unique challenge into a simple problem statement allowed me to search whether anyone had shared a solution. I found a post on Medium by Joseph Terranova that described a perfect solution. Joseph’s code only needed a few small additions to convert the data in the SNS message into a Slack post with all the details the operations team needed.
I followed Joseph’s instructions for creating a Slack webhook and SNS topic. Then I created my version of the Lambda function to complete the solution. My code is shown below. If you copy it, don’t forget to replace the values for:
- Slack webhook path (line 1)
- Slack channel (line 2)
- Slack posting username (line 3)
- Switch values (line 10-18)
- Message template (line 28)
This gave us automatic Slack posts that kept the operations team updated like the one shown below.
Exactly what we needed with the least amount of code.
Done. Did it.