How to send CloudWatch alarms to Microsoft Teams?
Andreas Wittig – 03 Aug 2020
So you have configured CloudWatch alarms to get notified when something goes wrong within your infrastructure running on Amazon Web Services? But how do you make sure your team notices whenever a CloudWatch alarm switches its state from OK
to ALARM
? Sending E-mails feels outdated. What about delivering CloudWatch alarms via Microsoft Teams?
In the following, you will learn how to send CloudWatch alarms to Microsoft Teams by using the following components:
- A CloudWatch alarm monitoring a metric.
- A CloudWatch event rule catching state change events of CloudWatch alarms.
- A Lambda function parses the alarm and sends an HTTPS request to the webhook.
- A Webhook delivers the message right into your team’s channel.
Next, you will learn to configure Microsoft Teams and deploy a CloudWatch event rule and Lambda function on AWS.
Are you looking for a managed solution?
marbot sends all CloudWatch Alarms to Microsoft Teams by default. You also get alert deduplication, contextual help, statistics, and much more.
- Add marbot to Slack or Microsoft Teams.
- Invite marbot to a channel.
- Follow the setup wizard in the channel.
Invite your team members to the channel.
Configuring Microsoft Teams
Open Microsoft Teams and go to the channel that you want to send CloudWatch alarms to. Open the menu and click on Connectors
.
Search for the connector named Incoming Webhook
maintained by Microsoft and press the Add
button.
Next, press the Add
button to add the connector to your channel.
Type in a name for the webhook, for example, CloudWatch Alarms
. Afterward, press the Create
button.
The webhook is now available. Copy the displayed URL https://outlook.office.com/webhook/...
.
That’s it. Microsoft Teams is ready to receive CloudWatch alarms. Next, you have to deploy a CloudWatch event rule and a Lambda function to your AWS account.
Deploying CloudWatch event rule and Lambda function
Are you looking for a simpler solution?
marbot sends all CloudWatch Alarms to Microsoft Teams by default. You also get alert deduplication, contextual help, statistics, and much more.
- Add marbot to Slack or Microsoft Teams.
- Invite marbot to a channel.
- Follow the setup wizard in the channel.
Invite your team members to the channel.
Deploy the Lambda function that connects to CloudWatch Alarms available at our GitHub repository widdix/cloudwatch-alarm-to-microsoft-teams. The following instructions guide you through the deployment process:
- Install the AWS CLI v1/v2.
- Configure the AWS CLI.
- Clone `git@github.com:widdix/cloudwatch-alarm-to-microsoft-teams.git` or download the respository.
- Select a region:
export AWS_REGION=us-east-1
. - Choose a unique suffix (replace
$UniqueSuffix
with e.g. your domain/username):export SUFFIX=$UniqueSuffix
. - Create an S3 bucket for SAM:
aws s3 mb s3://cw-to-teams-${SUFFIX}
- Install Node.js dependencies:
npm install
- Package the Lambda function code:
aws cloudformation package --s3-bucket cw-to-teams-${SUFFIX} --template-file template.yml --output-template-file template.sam.yml
- Deploy the CloudFormation stack (replace
$WebhookURL
with your URL from Microsoft Teams):aws cloudformation deploy --parameter-overrides "WebhookURL=$WebhookURL" --template-file template.sam.yml --stack-name cw-to-teams --capabilities CAPABILITY_IAM
That’s it. Sooner or later, you will receive a CloudWatch alarm via Microsoft Teams, shown in the following screenshot.
Keep your systems up and running!
Take your AWS monitoring to a new level! Chatbot for AWS Monitoring: Configure monitoring, escalate alerts, solve incidents.