AWS CodePipeline Alerts to Google Chat for Real-Time Notifications

Lajah ShresthaLajah Shrestha
3 min read

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:

  1. Create a Google Chat Space and Webhook URL.

  2. Configure CloudWatch Events to monitor pipeline failures.

  3. Set up an SNS topic to handle notifications.

  4. Process notifications with a Lambda function and send them to the Google Chat channel.


Step 1: Create a Google Chat Space and Webhook URL

  1. Create a Google Chat Space

    In Google Chat, create a space where you want the pipeline notifications to appear

    .

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

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

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

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

  1. Create a Lambda Function

    • Go to the AWS Lambda Console and create a new function named FnPipelineNotificationProcessor.

    • Select Python as the runtime.

  2. Deploy the Code

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

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

  1. Trigger a Pipeline Failure

    • Create a dummy pipeline or use an existing one.

    • Induce a failure to test the notification flow.

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

0
Subscribe to my newsletter

Read articles from Lajah Shrestha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Lajah Shrestha
Lajah Shrestha