· engineering · 4 min read
Setting up AWS EventBridge Notifications in Slack
Get a notification in your Slack channel whenever something occurs in AWS.
Table of Contents
Hooking up AWS EventBridge with a Slack webhook allows our team, to receive instant alerts when a wide variety of important events occur, for example if a CodeBuild pipeline fails, or an ECS task definition is updated. This real-time flow alerts not just to unexpected issues, but also slow, expected changes (such as the completion of a pipeline).
It’s very easy to setup, and can be deployed from a single cloudformation template without any code.
Getting slack ready
Before configuring AWS, you first need to prepare your Slack workspace:
- Create a Slack App
- Visit api.slack.com/apps, log in, and select ‘Create New App’.
- Choose ‘Create from scratch’, select your workspace, and then pick your team.
- Enable Incoming Webhooks:
- Navigate to the ‘Incoming Webhooks’ feature and enable it.
- Add a new webhook to the target channel of your workspace and copy the webhook URL.
This URL will be used by AWS EventBridge to send notifications to your Slack channel.
Responding to events
The premise is simple: When an event occurs in AWS, our eventbridgeRule will execute, the details we care about will be extracted from the event payload using an input transformer
, placed into a JSON template, and sent off to the slack webhook url.
Matching events with Rules
The majority of AWS services emit events, and there are lots that you might want to alert your team on, some of these include:
- Support case updates
- Certificate issued
- Certificate expired
- Certificate action required (very useful!)
- Cloudwatch alarms (configured not to match our autoscaling alarms)
- ECS deployments
- Codepipeline
- Codebuild
We can of course configure the rules to only trigger under certain conditions, allowing us to tailor the message (and emojis) as required, for example we can dispatch different messages for succesful and failed pipeline executions.
Here’s a full list of AWS services which generate events you can hook into to keep Slack notified in real-time.
The input transformer
Key to this implementation is the input transformer.
This allows us to extract certain details from the event body as variables, which can then be inserted into a template - in this case the JSON template that Slack requires for it webhooks.
The JSON template
The json template is built using block kit which allows us to render a nice message on our slack channel, we just need to add some placeholders for the input transformers using <greater and less that>
To get something like this:
We might use json like this:
Deployment with Cloudformation
The cloudfomration template below is a starting point - it configures necessary resources for the webhook and the role to use it with, from the WebHookUrl parameter.
It also includes an example rule, matching codepipeline failures.
You should extend this to cover all events you wish to be notified for.
Ideally you would use AWS Stacksets to deploy it automatically accross all your accounts and regions, giving your team insight automatically to any account added to your organisation.
Conclusion
This article demonstrates a practical use for EventBridge api destinations - in this case to send notifications to Slack - and how using some of the more advanced functionality of AWS, such as input transformers, can perform tasks that a Lambda might typically be used for.
Bear in mind that all notifcations can have an effect on your teams focus, take care to avoid overwhelming your colleagues with notifications and ensure important alerts remain prominent.
About James Babington
A cloud architect and engineer with a wealth of experience across AWS, web development, and security, James enjoys writing about the technical challenges and solutions he's encountered, but most of all he loves it when a plan comes together and it all just works.
No comments yet. Be the first to comment!