AWS CodePipeline Alerts to Google Chat for Real-Time Notifications

Search for a command to run...

No comments yet. Be the first to comment.
A year ago, attending AWS re:Invent felt impossible from where I stood. The cost of flights, accommodation in Las Vegas, and the conference pass itself added up to more than most engineers in Nepal ea

Implementation Guide of AWS

Accelerating speed in deployment is essential in today's competitive landscape, where user expectations for seamless and responsive applications are higher than ever. Rapid deployment allows organizations to quickly deliver new features, fix bugs, an...

From Planning to Presenting..

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.
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.
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.
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.
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:
url value (line 7) with the Google Chat webhook URL you saved earlier.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

.
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.

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.
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.