As more and more infrastructures are deployed in the cloud, there's a need to receive notification in case our cloud infrastructures experience some changes e.g. CPU utilization almost full, Virtual Machine changes status to Stopped, etc. While this notification feature is provided by Cloud Provider out of the box, we may need to subscribe the notification to various channels that we use individually. Also, message coming from cloud provider by default is not user-friendly and we need to convert it.
Using Courier, we can solve this issue. We can create notification template and integrate providers such as Email, SMS, and Slack in Courier, which then can be used by Cloud Provider serverless such as AWS Lambda or GCP Cloud Function to call and send notification to multi-channel. See Architecture below for more details.
- Python 3.9
- AWS Account
- Courier Account
- Twilio Account
- Slack Account
- Gmail Account
-
Follow Readme in this link to familiarize yourself with Courier and also to create accounts such as Gmail, Twilio, and Courier itself.
-
Follow this link especially the part that shows how to create Slack App. Once done, please add a channel (I call mine
#cloud-notification) in slack workspace and invite the bot to the channel. Take note of theChannel IDinAbouttab as it will be used in the lambda setup.
-
In the Courier app, go to Designer and then Create Template, name it anything you like, I use Cloud Notification as name. Configure 3 channels as per screen-shot below.
Click the gear icon at the top (near the Cloud Notification in the screen shot) and take Notification ID which will be used during lambda setup. -
Create your AWS account.
-
Create Standard SNS Topic in AWS account. Name it anything you like. My SNS topic in this tutorial is
dlm-notification. -
Create event bridge rule that reacts to any AWS event you like. In this setup, I'll focus on EC2 Instance State Change. Below screen-shots are provided to help you setup and please follow exactly the JSON when configuring the transformer in Event Bridge as the exact attributes are required to make the lambda (python code) work.
Full JSON for Template is below as the screen-shot can't display full value.{ "content": "EC2 Instance <instance> in account ID <account> and region <region> has changed state to <state>", "CloudProvider": "AWS", "Subject": "EC2 Instance State Change" }Feel free to configure tags if you like and create rule in Review and update.
-
Prepare lambda package by following below instructions:
- In terminal, go to folder that contains this README file, then run
pip install --target ./package trycourier - Then, run
cd package/ - Then, run
zip -r ../courier-lambda-package.zip . - Then, run
cd .. - Then, run
zip courier-lambda-package.zip index.py
-
Create AWS lambda that will host the python code. Below screen-shots and instructions are provided to help you setup the lambda.
Click Create Function at the bottom of the page, then upload the lambda package zip file created previously.
In the Configuration -> Permissions tab, add permission to invoke lambda from SNS in Resource-based policy statements. Pls change the SNS topic Arn with the one you configure (don't use what is in the screen-shot).
Then, in Configuration -> Environment Variables, make sure you setup environment variables for below variables. Get the value from your Courier and Slack environment. For DEST_EMAIL and DEST_PHONE, put any email and phone you'd like to use to get notification from cloud event.COURIER_TEMPLATEis Courier Notification ID.COURIER_TOKENis Courier API KeySLACK_CHANNELis Slack Channel ID
You can test the lambda by configuring test event or just creating EC2 instance and then changing the state of EC2. If it works, you'll see notification in your email, SMS, and slack channel.
- Convert manual step mentioned in this README to using Terraform, AWS SAM, or Serverless framework (Infra as Code).
- Add another AWS event in Event Bridge but ensuring the Input Transformer will output JSON with content, CloudProvider, and Subject attributes.
- Deploy the same function to another cloud provider e.g. GCP.
- As this is public repo, feel free to submit pull request in case you'd like to contribute to this project.
- The contribution could include: README update, converting this manual step into Infra as Code, adding another AWS event and configuring the proper Input Transformer, etc.

