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 年前256 查看次数
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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则