Learn a few tips and tricks for working with the AWS CLI to manage a CloudFormation stack.
Updated 1/7/2020: Added AWS CLI command to validate templates.
Errors in Stack
A CloudFormation stack can be created without errors but a stack can still fail to create or update its AWS resources. To check the status of your stack, run the following AWS CLI command. If StackStatus is something other than CREATE_COMPLETE you will need to investigate before you can run any update commands:
aws cloudformation describe-stacks --stack-name <stack-name>
Recreating the Stack
If you have errors creating your stack and need to run the create command, you will need to delete the stack first. Caution! Ensure you are deleting the right stack with this command there are no warnings or undo actions with command! Not only does the CloudFormation stack get deleted, but everything created by the stack as well (depending on policy). For more information about protecting a stack from deletion, see Protecting a stack from being deleted from AWS Documentation.
aws cloudformation delete-stack --stack-name <stack-name>
Updating CloudFormation Stack
To update a CloudFormation stack we update our template and then call the update-stack CLI command:
aws cloudformation update-stack --stack-name <stack-name> --template-body file://<updated-template-file>
You can use AWS CLI to validate your template before uploading to AWS with the following. Use the following CLI command, with the path to your template file:
aws cloudformation validate-template --template-body file://<PATH TO TEMPLATE>