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
已提問 2 年前檢視次數 262 次
1 個回答
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
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南