Monitoring CodePipeline deployments.

Jose López
December 12th, 2019 · 2 min read

This is the third article of a series of articles about monitoring.

-> First article: Monitoring CloudWatch key metrics using Slack and manage them using Terraform

-> Second article: APM using Datadog

-> Fourth article: Monitoring external services status using RSS and Slack

AWS CodePipeline is a fully managed continuous delivery service that helps you automate your release pipelines. CodePipeline automates the build, test, and deploy phases of your release process every time there is a code change, based on the release model you define.

In this article, we are going to focus on how to monitor CodePipeline deployments and push status reports to Slack. This way, we will have visibility when a deployment starts/succeeds/fails.

If you’re looking for an article describing CI/CD and how to setup AWS CodePipeline, check this article written by OBytes’ member Bouchaara Adil: Enable CI/CD with AWS developer tools

Alerting to Slack

We are going to use a CloudWatch Event Rule to capture every AWS CodePipeline state change for the Pipeline we choose. Besides this, we will need a Lambda function and an SNS topic to send messages to Slack. This is the same schema we used on the first article, changing the CloudWatch Alarm for a CloudWatch event rule.

CloudWatch Event Rule

Every change on a Pipeline emits a new CloudWatch Event, so, we will create a CloudWatch Event Rule to capture those events and notify the SNS topic that will invoke our Lambda function.

The CloudWatch Event Rule needs an Event Pattern which has the following format. As you see, you could capture the states you desire, for example notifying only for failed builds. In this case, we are going to notify when a build starts, fails or succeeds.

1{
2 "detail": {
3 "state": [
4 "STARTED",
5 "FAILED",
6 "SUCCEEDED"
7 ]
8 },
9 "detail-type": [
10 "CodePipeline Pipeline Execution State Change"
11 ],
12 "resources": [
13 "arn:aws:codepipeline:<REGION>:<ACCOUNT_ID>:<PIPELINE_NAME>"
14 ],
15 "source": [
16 "aws.codepipeline"
17 ]
18}

Then, you need to configure a target for the CloudWatch Event Rule. We will use an SNS topic. As input for the SNS topic, we will use the Pipeline name and the state, so we can create a custom message.

1input_transformer {
2 input_paths {
3 pipeline = "$.detail.pipeline"
4 state = "$.detail.state"
5 }
6
7 input_template = "\"The pipeline *<pipeline>* has *<state>*.\""
8 }

SNS and Lambda function

We will use the same SNS topic and Lambda function than in the first article. You can find them in the source code of this article, along with the Terraform code for the CloudWatch Event Rule.

You’ll also need to create a Slack webhook and set it as an ENV variable for the Lambda function.

Slack

Once all the parts are ready, you’ll notifications like the following in the Slack channel you configured.

Thanks for reading!

In this article, we created notifications for your CI/CD to Slack. This will help you gain visibility over builds and be aware of the status of your deployments. In the final article of this series, we will set up notifications for external services (AWS, GitHub, DockerHub…) used on our stack. Stay tuned!

More articles from Obytes

APM using Datadog.

Application performance management (APM) on a Django application running on ECS Fargate using Datadog APM.

December 6th, 2019 · 2 min read

Monitoring CloudWatch key metrics using Slack and manage them using Terraform.

Key metrics to monitor using AWS CloudWatch, track them using Slack and manage them using Terraform.

November 18th, 2019 · 2 min read

ABOUT US

Our mission and ambition is to challenge the status quo, by doing things differently we nurture our love for craft and technology allowing us to create the unexpected.