AWS CodePipeline Alerts to Google Chat for Real-Time Notifications


In this guide, you'll learn how to integrate AWS CodePipeline notifications into Google Chat using CloudWatch, SNS, and a Lambda function. This solution provides real-time updates to your Google Chat space when a pipeline fails.
Steps Overview:
Create a Google Chat Space and Webhook URL.
Configure CloudWatch Events to monitor pipeline failures.
Set up an SNS topic to handle notifications.
Process notifications with a Lambda function and send them to the Google Chat channel.
Step 1: Create a Google Chat Space and Webhook URL
Create a Google Chat Space
In Google Chat, create a space where you want the pipeline notifications to appear
.
Set Up Webhook Integration
Navigate to the space, click the dropdown menu, and go to Apps & Integrations.
Select Manage Webhooks to generate a webhook URL.Note: Webhooks can only be created in Workspace accounts (not personal Google accounts), and the
administrator must enable this feature.
Save the Webhook URL
Save the generated webhook URL. You'll use it later in the Lambda function.
Step 2: Configure CloudWatch to Monitor Pipeline Failures
AWS CodePipeline provides basic notifications for Slack, but for custom solutions like Google Chat, we’ll use CloudWatch.
Create a CloudWatch Event Rule
Go to CloudWatch > Buses > Rules > Create Rule.
Configure the rule to listen for CodePipeline execution state changes:
Event Source: AWS CodePipeline
Event Type: CodePipeline Action Execution State Change
Specific State: FAILE
D
Set the Target as an SNS Topic
Under the Target section, create an SNS topic.
Allow CloudWatch to send events to this SNS topic.
Step 3: Process Notifications with a Lambda Function
The Lambda function will process the SNS notification and send the formatted message to Google Chat.
Create a Lambda Function
Go to the AWS Lambda Console and create a new function named
FnPipelineNotificationProcessor
.Select Python as the runtime.
Deploy the Code
Clone the repository from:https://github.com/LajahShrestha/AWSPipelineNotificationProcessor
Modify the
lambda_function.py
file:- Replace the
url
value (line 7) with the Google Chat webhook URL you saved earlier.
- Replace the
Zip the code and upload it to an S3 bucket.
Upload Code to Lambda
In the Lambda console, upload the zipped file from S3.
Increase the timeout (under the Configuration tab) to around 10 minutes.
Add SNS as a Trigger
Add the SNS topic you created as a trigger for the Lambda function.
Ensure the Lambda execution role has sufficient permissions to read from SNS
.
Step 4: Testing the Integration
Trigger a Pipeline Failure
Create a dummy pipeline or use an existing one.
Induce a failure to test the notification flow.
Verify Notifications
Check your Google Chat space for pipeline failure notifications.
If no notifications appear, review the Lambda function logs in CloudWatch.
Debugging Tips
Webhook Issues: Ensure the Google Chat webhook URL is valid and accessible.
Lambda Logs: Check CloudWatch logs for any processing errors.
Permissions: Verify the Lambda execution role has permissions to subscribe to and process SNS messages.
Event Rule: Ensure the CloudWatch event rule is correctly configured to capture the desired pipeline state changes.
Conclusion
With this setup, you can efficiently monitor AWS CodePipeline failures in Google Chat, ensuring prompt action when issues arise. This integration leverages the flexibility of CloudWatch, SNS, and Lambda to provide real-time notifications.
For further reference, check out this detailed tutorial on Medium.
Subscribe to my newsletter
Read articles from Lajah Shrestha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
