Alerting via Microsoft Teams

1. Introduction ▾

Using Lambda as a CloudWatch Alarm action, offers flexibility in the notification channels and remediation actions.

In this example, a Lambda Function is used to publish CloudWatch Alarm Notifications to a Teams channel. As a prerequisite, a webhook must be created for the channel prior to deployment.

CloudWatch Alarm integration with Microsoft Teams
Fig 1: CloudWatch Alarm integration with Microsoft Teams
  • The ALB emits HTTPCode_ELB_502_Count datapoints to CloudWatch.
  • CloudWatch Alarm threshold is breached and transitions to ALARM state.
  • CloudWatch posts a JSON object to Lambda.
  • Lambda parses the JSON object for alarm_name, description, reason and timestamp fields and creates an Adaptive Card.
  • Lambda then publishes the Adaptive Card to a Teams channel using the webhook URL.
  • This code can be customized and extended to match your use case.
⬇ CloudFormation Template: CloudWatch Alarm Teams Notification

2. Sample Lambda Source ▸

3. Alarm Breached Threshold ▾

CloudWatch Alarm transitioned to ALARM State
Fig 1: CloudWatch Alarm transitioned to ALARM State

4. Alarm Notification Delivered to Teams Channel ▾

Teams Notification
Fig 2: CloudWatch Alarm Notification successfully delivered to Teams Channel