Monitoring and alerting are key pillars of any production-grade AWS environment. In this guide, I’ll walk you through integrating AWS CloudWatch Alarms with Google Chat using Amazon SNS and a Lambda function ideal for teams using Google Workspace instead of Slack or Microsoft Teams.
🎯 Use Case
My ECS service scales up when CPU or memory exceeds 75%. I want real-time alerts in Google Chat—not just email.
🚧 The Challenge
While CloudWatch can trigger alarms and send notifications via SNS, Google Chat isn't a native target. SNS supports protocols like email, Lambda, SQS, and HTTP/S—but not Google Chat directly.
✅ The Solution
We can bridge the gap with this flow:
CloudWatch Alarm → SNS Topic → Lambda Function → Google Chat Webhook
🧰 Prerequisites
To complete this integration, you'll need:
- An AWS account with permission to create SNS topics and Lambda functions
- A Google Chat space with an active webhook URL
- Basic Python and AWS Lambda familiarity
🔧 Step 1: Set Up a Google Chat Webhook
- In Google Chat, open or create a Space.
- Click the arrow next to the space name → Manage Webhooks.
- Click Add Webhook, name it (e.g.,
AWS Alerts
), and copy the Webhook URL.
🐍 Step 2: Write Your Lambda Function (Python)
Create a simple Lambda function to forward SNS messages to Google Chat using httplib2
.
lambda_function.py
from httplib2 import Http
from json import dumps
def lambda_handler(event, context):
url = "<WEBHOOK-URL>" # Replace with your actual webhook URL
message = {'text': event['Records'][0]['Sns']['Message']}
headers = {'Content-Type': 'application/json; charset=UTF-8'}
http_obj = Http()
response = http_obj.request(
uri=url,
method='POST',
headers=headers,
body=dumps(message)
)
return response
📦 Step 3: Package the Lambda Code
On any Linux machine:
mkdir -p python/lambda
cd python/lambda
# Add your lambda_function.py here
vi lambda_function.py
# Install dependencies
pip3 install httplib2 -t .
pip3 install requests -t .
# Zip the code
zip -r python_code.zip .
⚠️ Install pip3 if missing:
Ubuntu/Debian:sudo apt install python3-pip
RHEL/CentOS:sudo dnf install python3-pip
🚀 Step 4: Deploy the Lambda Function
- Go to AWS Lambda → Create function
- Choose Author from scratch
- Set Runtime to Python 3.x
- Upload
python_code.zip
under Function Code - Set the Handler to
lambda_function.lambda_handler
- Click Deploy
🧪 Step 5: Test the Integration
Manual Test (Lambda)
- In your Lambda function, click Test
- Select the SNS Topic Notification template
- Use the default sample event
- Confirm the alert is posted in your Google Chat room
📢 Step 6: Set Up SNS Topic & Subscription
Create SNS Topic
- Go to Amazon SNS → Topics → Create topic
- Choose Standard
- Name it something like
alert-notifications
- Click Create topic
Subscribe Lambda to SNS
- Go to Subscriptions → Create subscription
- Set protocol to AWS Lambda
- Select your deployed Lambda function
- Confirm the subscription
Manual Test (SNS)
- In the SNS topic, click Publish message
- Add a subject and message body
- Publish and check Google Chat for the alert
✅ Final Thoughts
With this integration, you can pipe AWS alerts directly into Google Chat—keeping your team informed in real time, even if you're not using Slack or Microsoft Teams.
You can attach this SNS topic to any CloudWatch alarm or event, including:
- ECS Service scaling
- EC2 high CPU alerts
- ALB 5XX errors
🔗 Resources
If you found this useful, follow me for more practical AWS DevOps content.
Let’s keep building resilient cloud-native systems—one alert at a time!
Tags:
#DevOps #CloudEngineer #AWS #GoogleChat #Lambda #SNS #Alerting #Monitoring #CloudWatch #Automation #AWSCommunityBuilders
Top comments (0)