Rollbar Deployment Updates from AWS CodePipeline

We have used Rollbar as a tool for error reporting at TrainingPeaks for many years. Like most error reporting tools, Rollbar can be notified of deployments.

We recently upgraded one of our services to .NET core. We use CodePipeline for the CI/CD process to build, test, and deploy into containers running in AWS Fargate. When the CodeBuild step is successful, a container image is created and pushed to an Elastic Container Registry (ECR) and tagged with the commit hash. Deployment runs CodePipline CloudFormation Actions for each environment to create and rotate in new containers of the image.

This process works extremely well, but left behind our ability to notify Rollbar on deploy.

Our Solution: CodePipeline Lambda Actions

CodePipeline has the ability to call an AWS Lambda function, which is exactly what we need to notify Rollbar after a successful deploy.

CodePipline Visualization

The Lambda Function

The first task was to write a lambda function to integrate into CodePipeline. For that we used the AWS Serverless Application Framework (SAM) and Python. The lambda function needed to accomplish two things:

This requires permissions to access CodePipeline, handled by adding the SAM CodePipelineLambdaExecutionPolicy to the function.

The Rollbar SAM Function Template

The function receives a CodePipeline event, validates the passed in UserParameters, and updates CodePipeline using boto3. UserParameters is a string we defined as the following JSON structure containing the values needed for Rollbar:

{
"access_token" : "xxxx",
"revision" : "GITSHA",
"environment" : "production"
}

To this data, the function adds the local_username value consisting of a string containing the CodePipeline Job Id. It uses the requests library to POST via HTTP to the Rollbar API endpoint.

Rollbar Lambda Function

The CodePipeline Action CloudFormation

The final step adds a CodePipeline Invoke Action that calls the lambda function, passing the required data. It takes advantage of the new CodePipeline Variables feature, to pass the CommitId from the source stage to the function by adding Namespace: SourceVariables the Source action.

CodePipeline Invoke Action CloudFormation

Conclusion

We continuously update and improve our systems to better support our customers. We use key SRE and DevOps principles including monitoring, logging, and alerting to not only know how our systems are operating, but as fast feedback to respond and improve. Sending Rollbar deploy information improves our ability to correlate increased error rates with deployments, and better serve our customers.

Husband, Father, Software Developer, Cyclist, White Gold Wielder