How to cleanup resources when a CodePipeline stage execution fails?

0

I like to implement an integration test stage as part of a CodePipeline CI/CD pipeline. Within this stage I expect to have two actions: 1) deploy the code to an integration environment using CloudFormation and 2) run a suite of integration tests against this deployment. After that the pipeline would move on to other stages like deploying to production for example.

Now assume that the integration test suite fails. How can I ensure that the deployed resources are cleaned up? All documentation and examples I've seen so far don't address this scenario.

Sub-question: Would you recommend having a long-lived integration environment that changes alongside production or would you rather create a fresh integration stack from scratch for each pipeline execution? Arguments for the former would be that you would test the actual stack update that would also be applied to the production stack and it would also be faster if your stack contains resources that take a while to create (DynamoDB tables for example). The drawback would be that in case the integration test suite fails the cleanup would need to revert the applied change set instead of just tearing down the entire stack.

Martin
asked 2 years ago241 views
1 Answer
1

Hey - CodePipeline events can be monitored so that a failure could trigger an action. There is an existing pattern for custom triggers for AWS CodePipeline with AWS Lambda and Amazon CloudWatch Events.

As for your second question, you may also want to consider the costs of running a long-lived integration environment.

profile pictureAWS
Jake
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions