3

I am using sam deploy command to deploy my lambda to AWS. Sometimes I get this error An error occurred (ValidationError) when calling the CreateChangeSet operation: Stack:arn:aws:cloudformation:ap-southeast-2:xxxx:stack/xxxx/xxxx is in ROLLBACK_COMPLETE state and can not be updated. I know there is a failure happens on the previous deployment. I can manually delete the stack in AWS cloundformation console and retry the command. But I wonder is there is way to force the command to delete any rollback state stack?

I know I can delete the failed stack via aws cli or console. But my deploy script is on CI and I'd like to make CI to use deploy command to override the failed stack. So the scenario is:

1. CI failed on deploy lambda function
2. My team analysis the issue and fix the issue in cloudformation template file
3. Push the fix to github to tigger the CI
4. CI is triggered and use the latest change to override the failed stack.

I don't want the team to manually delete the stack.

1 Answer 1

3

The ROLLBACK_COMPLETE status exists only after a failed stack creation. The only option is to delete the stack. This is to give you a chance to correctly analyze the reason behind the failure.

You can delete the stack from the command line with:

aws cloudformation delete-stack --stack-name <value>

From the documentation of ROLLBACK_COMPLETE:

Successful removal of one or more stacks after a failed stack creation or after an explicitly canceled stack creation. Any resources that were created during the create stack action are deleted.

This status exists only after a failed stack creation. It signifies that all operations from the partially created stack have been appropriately cleaned up. When in this state, only a delete operation can be performed.

Normally the ROLLBACK_COMPLETE should not happen in production. I would suggest validating your stack in a development environment or have one successful stack creation in your production environment before continuously deploying your stack.

Still, you could have a custom script in your CI that checks the stack status (DescribeStacks) and if it's ROLLBACK_COMPLETE delete it (DeleteStack). This script would run before sam deploy.

Sign up to request clarification or add additional context in comments.

2 Comments

I know I can delete the stack via command or aws console. But the deploy command is written in CI and is there a way for CI to use deploy command to force delete the failed stack?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.