Member-only story
How to Let Slack Notify You on Cloudwatch Errors With AWS Lambda
Don’t look for errors, let them call you

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:
- Serverless CLI installed.
- Basic knowledge of Typescript.
- 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’.

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.

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]

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…