DEV Community

Cover image for Send AWS CloudWatch Alerts to Google Chat Using SNS and Lambda
Samuel Ajisafe
Samuel Ajisafe

Posted on • Edited on

Send AWS CloudWatch Alerts to Google Chat Using SNS and Lambda

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
Enter fullscreen mode Exit fullscreen mode

🧰 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

  1. In Google Chat, open or create a Space.
  2. Click the arrow next to the space name → Manage Webhooks.
  3. 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
Enter fullscreen mode Exit fullscreen mode

📦 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 .
Enter fullscreen mode Exit fullscreen mode

⚠️ Install pip3 if missing:
Ubuntu/Debian: sudo apt install python3-pip
RHEL/CentOS: sudo dnf install python3-pip


🚀 Step 4: Deploy the Lambda Function

  1. Go to AWS LambdaCreate function
  2. Choose Author from scratch
  3. Set Runtime to Python 3.x
  4. Upload python_code.zip under Function Code
  5. Set the Handler to lambda_function.lambda_handler
  6. Click Deploy

🧪 Step 5: Test the Integration

Manual Test (Lambda)

  1. In your Lambda function, click Test
  2. Select the SNS Topic Notification template
  3. Use the default sample event
  4. Confirm the alert is posted in your Google Chat room

📢 Step 6: Set Up SNS Topic & Subscription

Create SNS Topic

  1. Go to Amazon SNSTopicsCreate topic
  2. Choose Standard
  3. Name it something like alert-notifications
  4. Click Create topic

Subscribe Lambda to SNS

  1. Go to SubscriptionsCreate subscription
  2. Set protocol to AWS Lambda
  3. Select your deployed Lambda function
  4. Confirm the subscription

Manual Test (SNS)

  1. In the SNS topic, click Publish message
  2. Add a subject and message body
  3. 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)