What if you could change your entire cloud setup with just one simple command?
Why Updating and deleting stacks in AWS? - Purpose & Use Cases
Imagine you built a house by hand, brick by brick, and now you want to change a window or remove a wall. Doing this manually means tearing down parts and rebuilding everything from scratch, which takes a lot of time and effort.
Manually updating or deleting cloud resources is slow and risky. You might forget to remove some parts or accidentally break others. It's like trying to fix a puzzle without knowing if all pieces fit, causing errors and downtime.
Using stack updates and deletions lets you manage your cloud resources safely and automatically. You tell the system what changes you want, and it carefully applies them, keeping everything working smoothly without manual hassle.
Delete each resource one by one in console or CLI Manually change each resource configuration
aws cloudformation update-stack --stack-name MyStack --template-body file://template.yaml aws cloudformation delete-stack --stack-name MyStack
You can quickly and safely change or remove your entire cloud setup with a single command, avoiding mistakes and saving time.
A company needs to add more servers to handle more users. Instead of manually creating each server, they update their stack template and run one command to add all servers automatically.
Manual changes are slow and error-prone.
Stack updates automate safe changes to cloud resources.
Deleting stacks removes all resources cleanly with one command.
Practice
update-stack command in AWS CloudFormation?Solution
Step 1: Understand the role of update-stack
Theupdate-stackcommand is used to modify resources that are already managed by an existing CloudFormation stack.Step 2: Differentiate from other commands
Unlikedelete-stackwhich removes resources,update-stackchanges them safely without deleting the stack.Final Answer:
To safely change existing cloud resources managed by a stack -> Option BQuick Check:
update-stack = change resources safely [OK]
- Confusing update-stack with delete-stack
- Thinking update-stack creates new stacks
- Assuming update-stack lists stacks
MyAppStack?Solution
Step 1: Identify the correct delete command
The correct AWS CLI command to delete a stack isdelete-stackwith the parameter--stack-name.Step 2: Verify syntax correctness
aws cloudformation delete-stack --stack-name MyAppStack uses the exact syntax:aws cloudformation delete-stack --stack-name MyAppStack, which is valid and deployable.Final Answer:
aws cloudformation delete-stack --stack-name MyAppStack -> Option AQuick Check:
delete-stack + --stack-name = correct syntax [OK]
- Using update-stack instead of delete-stack
- Wrong parameter names like --name or --stack
- Using non-existent commands like remove-stack or destroy-stack
aws cloudformation update-stack --stack-name TestStack --template-body file://template.json aws cloudformation describe-stacks --stack-name TestStack
What is the expected behavior after running these commands?
Solution
Step 1: Understand update-stack effect
Theupdate-stackcommand modifies the existing stack named TestStack using the provided template.Step 2: Describe-stacks shows current stack status
Thedescribe-stackscommand retrieves details about TestStack, including its updated status.Final Answer:
The stack TestStack is updated with the new template, and its status is shown -> Option AQuick Check:
update-stack changes stack + describe-stacks shows status [OK]
- Thinking update-stack deletes the stack
- Assuming describe-stacks creates a new stack
- Believing update-stack and describe-stacks cannot be used sequentially
aws cloudformation update-stack --stack-name ProdStack --template-body file://newtemplate.json but get an error saying the stack is in UPDATE_IN_PROGRESS state. What should you do to fix this?Solution
Step 1: Understand stack states during update
When a stack is inUPDATE_IN_PROGRESS, it means an update is already running and must complete before another update starts.Step 2: Choose the correct action
Waiting for the current update to finish avoids conflicts and errors. Deleting or renaming the stack is unnecessary and may cause data loss or confusion.Final Answer:
Wait for the current update to finish before running update-stack again -> Option DQuick Check:
UPDATE_IN_PROGRESS means wait before next update [OK]
- Trying to delete stack during update
- Renaming stack instead of waiting
- Ignoring error and retrying immediately
update-stack to achieve this?Solution
Step 1: Understand rollback behavior in update-stack
By default, CloudFormation rolls back stack updates on failure. The--disable-rollbackoption disables this behavior.Step 2: Identify the correct option to keep rollback enabled
To ensure rollback happens automatically on failure, you should NOT disable rollback. Therefore, do not use--disable-rollback. The default behavior is rollback enabled, so omit this option or explicitly avoid disabling rollback.Step 3: Analyze options
--rollback-configurationis for configuring alarms,--enable-rollbackand--no-rollbackare not valid AWS CLI options.Final Answer:
--disable-rollback disables rollback; omit it to keep rollback enabled -> Option CQuick Check:
Omit --disable-rollback to keep rollback on failure [OK]
- Using non-existent --enable-rollback option
- Confusing disable-rollback disables rollback
- Assuming rollback is off by default
Ready to prove it?
Pass the test and this pattern moves unknown
