AWS Messaging Blog
Integrate Amazon CloudWatch alarms with WhatsApp using AWS End User Messaging
Timely and accessible alert notifications are crucial for maintaining operational excellence, but traditional alerting mechanisms often fall short. Email notifications can get buried in crowded inboxes, SMS messages might incur high costs for international teams, and pager systems lack the rich context modern teams need for rapid incident response. WhatsApp, with over 2 billion users worldwide, offers several advantages:
- Universal accessibility – Available on virtually every smartphone
- Rich media support – Sends formatted messages, images, and links
- Global reach – No international SMS fees
- High engagement – Messages are typically delivered within seconds
- Familiar interface – Many teams already use WhatsApp for daily communication
This post walks through a solution to build a serverless alerting system that delivers Amazon CloudWatch alarms to WhatsApp using AWS End User Messaging.
Overview of solution
The solution uses AWS End User Messaging Social to create a seamless bridge between CloudWatch alarms and WhatsApp notifications. This serverless architecture provides real-time infrastructure alerts through WhatsApp messaging platform teams already know and use.
The architecture consists of four main AWS services working together. The data flow begins when CloudWatch alarms detect breaches of predefined thresholds and publish notifications to an Amazon Simple Notification Service (Amazon SNS) topic. The SNS topic triggers an AWS Lambda function that processes the alarm data, formats contextual WhatsApp messages, and uses AWS End User Messaging Social to deliver notifications to specified recipients.
The following diagram illustrates the solution architecture.
Prerequisites
Implementation requires an AWS account with appropriate permissions for AWS CloudFormation, Lambda, Amazon SNS, and CloudWatch. You must also have a WhatsApp Business Account integrated with AWS End User Messaging and the WhatsApp phone number ID from the AWS End User Messaging console. (For instructions to locate this information, see View a phone number’s ID in AWS End User Messaging Social).
For more information about how to set up WhatsApp using AWS End User Messaging Social, refer to Automate workflows with WhatsApp using AWS End User Messaging Social.
Before you deploy this solution, create an approved template in your Meta account named cw_alarm_notification
. Alternatively, use your preferred template name and modify the Lambda function code accordingly (as shown in the following screenshot).
Lambda function code
The solution uses a Python-based Lambda function that processes CloudWatch alarm notifications and formats them for WhatsApp delivery. The function receives SNS events containing CloudWatch alarm data, extracts relevant information, formats contextual messages, and delivers notifications through AWS End User Messaging Social.
The following function code shows an example to parse the SNS message content and extract key alarm information, including alarm name, state value, and reason for state change:
The following code shows an example to create a template message for WhatsApp (you can change the template name if required):
The send_whatsapp_message
function uses AWS End User Messaging Social to deliver formatted messages through the socialmessaging
client:
Deploy the solution
The solution uses AWS CloudFormation for infrastructure as code (IaC) deployment. The main template creates an SNS topic for alarm notifications, a Lambda function for message processing, and required AWS Identity and Access Management (IAM) roles with least-privilege permissions.
The CloudFormation template requires a recipient number with an active WhatsApp account to receive alarm notifications as messages. The template also requires the WhatsApp phone number ID retrieved from the AWS End User Messaging Social console, as noted in the prerequisites. The template must be deployed in the same AWS Region as AWS End User Messaging Social. See the following code:
The preceding template deploys an alarm called SampleHighCPUAlarm
that triggers an SNS topic. The SNS topic triggers the WhatsApp alarm notifier Lambda function, which processes and sends the message using AWS End User Messaging Social.
Test the solution
You can test the solution using the sample alarm created by the CloudFormation stack. The following screenshot shows an example alarm configuration and its CloudWatch metrics, currently in the OK state.
You can use the following code to trigger the alarm by updating this metric:
As the alarm switches from OK to ALARM state, a WhatsApp Message is delivered.
Conclusion
Integrating CloudWatch with WhatsApp notifications represents a significant step forward in modern infrastructure monitoring. By using AWS End User Messaging, teams can receive critical alerts through their preferred communication channel while maintaining the reliability and scalability of AWS services.
The solution’s modular architecture, simple yet effective security model, and cost-effective design make it suitable for organizations of various sizes.