Slack Notifications for Alerting (via AWS Lambda)
Alex Reynolds
Published on December 21, 2023
You might have encountered situations where you wanted to send status alerts or notifications to a Slack channel. When working with AWS Alarms, there’s already an app (AWS Chatbot) that can send notifications directly to your Slack channels. However, if you are working with external tools, for example databases or file systems, you might need a custom solution.
My Use Case:
An external service occasionally exports data (parquet files) to my S3 bucket. Each new file that arrives in my S3 bucket is an indication that there’s something wrong with the data and that the team needs to be notified via Slack. While notifying the team, I also want to include some meaningful information about the data itself (e.g., row count).
Now, how do we send a notification to Slack every time there’s a new incoming file? To solve this problem, I utilised an S3 event-based trigger, a Lambda function, and a Slack webhook.
Slack Incoming Webhooks:
If you head to the Slack App Directory, you can find the Incoming webhooks app. Incoming webhooks are a simple way to post messages from external sources into Slack. They use HTTP requests with a JSON payload. The payload includes the message as well as other optional details. Once you have setup the webhook, you will obtain a URL which can be used later in your Lambda function.
During the setup, you also have the option to upload an image that is used while sending messages (or notifications). You can send Slack messages that looks like this: