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?

How to send CloudWatch alarms to 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.

Overview

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.

  1. Add marbot to Slack or Microsoft Teams.
  2. Invite marbot to a channel.
  3. Follow the setup wizard in the channel.
  4. 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.

Configure Microsoft Teams: Step 1

Search for the connector named Incoming Webhook maintained by Microsoft and press the Add button.

Configure Microsoft Teams: Step 2

Next, press the Add button to add the connector to your channel.

Configure Microsoft Teams: Step 3

Type in a name for the webhook, for example, CloudWatch Alarms. Afterward, press the Create button.

Configure Microsoft Teams: Step 4

The webhook is now available. Copy the displayed URL https://outlook.office.com/webhook/....

Configure Microsoft Teams: Step 5

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.

  1. Add marbot to Slack or Microsoft Teams.
  2. Invite marbot to a channel.
  3. Follow the setup wizard in the channel.
  4. 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:

  1. Install the AWS CLI v1/v2.
  2. Configure the AWS CLI.
  3. Clone `git@github.com:widdix/cloudwatch-alarm-to-microsoft-teams.git` or download the respository.
  4. Select a region: export AWS_REGION=us-east-1.
  5. Choose a unique suffix (replace $UniqueSuffix with e.g. your domain/username): export SUFFIX=$UniqueSuffix.
  6. Create an S3 bucket for SAM: aws s3 mb s3://cw-to-teams-${SUFFIX}
  7. Install Node.js dependencies: npm install
  8. Package the Lambda function code: aws cloudformation package --s3-bucket cw-to-teams-${SUFFIX} --template-file template.yml --output-template-file template.sam.yml
  9. 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.

CloudWatch Alarm via Microsoft Teams

Keep your systems up and running!

Andreas Wittig

Andreas Wittig

Consultant focusing on Amazon Web Services (AWS). Entrepreneur building marbot.io. Author of Amazon Web Services in Action, Rapid Docker on AWS, and cloudonaut.io.

You can contact me via Email, Twitter, and LinkedIn.

Published on

marbot teaser

Chatbot for AWS Monitoring

Configure monitoring for Amazon Web Services: CloudWatch, EC2, RDS, EB, Lambda, and more. Receive and manage alerts via Slack. Solve incidents as a team.

Slack
Add to Slack
Microsoft Teams
Add to Teams