Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke Lambda function on CodePipeline Stage or Action Failure

When CodePipeline creates production assets we're required to file a Request For Change.

Opening the RFC when entering the Production Stage and closing the RFC on a successful Production build/test is easy enough by firing Lambdas. The question comes when a CodePipeline Stage or Test Action fails.

How to fire Lambda when a CodePipeline Stage fails? Similarly how to fire a Lambda when a CodePipeline Test Action fails?

Example cloudformation

like image 683
Eric Nord Avatar asked Oct 16 '25 05:10

Eric Nord


2 Answers

From AWS:

The ability to get notified with the relevant details when a pipeline fails to complete is a popular feature request (asked by multiple customers and very valid use-case to have) and I can confirm that it is on the service team roadmap but they haven't provided an ETA on this request (I would recommend checking the release history page for this service : link https://aws.amazon.com/releasenotes/AWS-CodePipeline )

As an alternative, other ways to implement this functionality using Lambda are listed below:

1) Have a Lambda function which polls the pipeline state using time based CloudWatch events and triggers an SNS notification when it sees a failed action.

2) Put a Lambda function using our Lambda integration as a parallel action to the action you want to monitor then monitor the status of the other action from within the Lambda function to see if it fails or succeeds. Use continuation tokens to ensure the Lambda function keeps getting invoked until it sees a result in the other action, and send an SNS notification accordingly.

like image 173
Eric Nord Avatar answered Oct 19 '25 06:10

Eric Nord


As of July 12, 2017, Amazon has announced the availability of this feature.

Announcement: Amazon CloudWatch Events now supports AWS CodePipeline as a target

In the Cloudwatch console, you can already see it as a target.

enter image description here

like image 44
Noel Llevares Avatar answered Oct 19 '25 06:10

Noel Llevares