Better Programming

Advice for programmers.

Follow publication

How to Let Slack Notify You on Cloudwatch Errors With AWS Lambda

Don’t look for errors, let them call you

Haiko van der Schaaf
Better Programming
Published in
4 min readMay 2, 2022

--

Photo by Rubaitul Azad on Unsplash

Would it not be nice to be notified when something goes awry? In case it is running on AWS you are in luck because AWS Lambda can listen to Cloudwatch Log streams. In this story, I would like to demonstrate how you can act on errors in the Cloudwatch Log stream with AWS Lambda and then send a notification to Slack.

Prerequisites:

  1. Serverless CLI installed.
  2. Basic knowledge of Typescript.
  3. AWS account.

Setup Slack App

Create an account on Slack if you do not already have one. Next, create a Slack app using these instructions. I have created the app ‘ExampleLibraryLogs’.

Create a Slack app

The next step is to activate an incoming webhook you can use to post notifications. Use the menu on the left to navigate to the ‘Incoming Webhooks’ menu item. Add a webhook and select a slack channel. I have selected the #general channel.

incoming webhook

Navigate to menu item ‘OAuth & Permissions’ and write down the ‘Bot User OAuth Token’. It should start with ‘xoxb-’.

With the webhook, you are now able to post messages on the chosen Slack channel. The last thing to do here is to invite your app to the selected channel in Slack by typing /invite @[appname]

invite APP in the Slack channel

Serverless setup

We will expand on creating an online library service discussed in an earlier story and create a monitor for the service. The monitor service will trigger on exceptions…

--

--

Haiko van der Schaaf
Haiko van der Schaaf

Written by Haiko van der Schaaf

Cloud Architect | Serverless Advocate | Blogger | AWS Certified 🚀

Responses (1)

Write a response