Bird
Raised Fist0
AWScloud~10 mins

Updating and deleting stacks in AWS - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Updating and deleting stacks
Create or have existing stack
↓
Decide to update stack?
No→Exit
Yes↓
Prepare updated template or parameters
↓
Submit update request
↓
CloudFormation processes update
↓
Update success?
No→Rollback changes
Yes↓
Stack updated
↓
Decide to delete stack?
No→Exit
Yes↓
Submit delete request
↓
CloudFormation deletes resources
↓
Stack deleted
↓
End
This flow shows how you update an existing stack by submitting changes, then optionally delete the stack to remove all resources.
Execution Sample
AWS
aws cloudformation update-stack --stack-name MyStack --template-body file://update.yaml
aws cloudformation delete-stack --stack-name MyStack
Update a stack named MyStack with a new template, then delete the stack.
Process Table
StepActionInputCloudFormation BehaviorResult
1Check if stack existsStack: MyStackStack foundReady for update
2Submit update requestTemplate: update.yamlValidates template, compares changesUpdate in progress
3Process updateChanges detectedUpdates resources as neededResources updated
4Update success?Update statusYesStack updated successfully
5Decide to delete stackUser input: YesAccept delete requestDelete in progress
6Process deleteDelete stack MyStackDeletes all stack resourcesStack deleted
7Check stack existenceStack: MyStackStack not foundEnd - stack removed
💡 Stack is deleted, no longer exists in CloudFormation
Status Tracker
VariableStartAfter Step 2After Step 4After Step 6Final
Stack StatusCREATE_COMPLETEUPDATE_IN_PROGRESSUPDATE_COMPLETEDELETE_COMPLETEDELETE_COMPLETE (stack removed)
Key Moments - 3 Insights
Why does the stack status change to UPDATE_IN_PROGRESS after submitting an update?
Because CloudFormation starts applying the changes, as shown in execution_table step 2 and 3, the status reflects the ongoing update process.
What happens if the update fails during processing?
CloudFormation rolls back to the previous stable state, preventing partial updates. This is implied in the flow after step 3 if update success is No.
Does deleting a stack remove all its resources automatically?
Yes, as shown in execution_table step 6, deleting the stack triggers deletion of all resources created by that stack.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the stack status after step 4?
ACREATE_COMPLETE
BDELETE_IN_PROGRESS
CUPDATE_COMPLETE
DUPDATE_IN_PROGRESS
💡 Hint
Check the 'Stack Status' variable in variable_tracker after step 4
At which step does CloudFormation start deleting the stack resources?
AStep 4
BStep 6
CStep 5
DStep 7
💡 Hint
Refer to execution_table row where 'Process delete' action happens
If the update fails during processing, what would happen in the execution flow?
ACloudFormation rolls back to previous stack state
BStack is deleted immediately
CStack status changes to DELETE_IN_PROGRESS
DUpdate completes successfully
💡 Hint
See key_moments explanation about update failure and rollback
Concept Snapshot
Updating and deleting stacks in AWS CloudFormation:
- Update stack by submitting new template or parameters
- CloudFormation validates and applies changes
- If update fails, rollback restores previous state
- Delete stack to remove all resources
- Stack status shows progress (UPDATE_IN_PROGRESS, DELETE_IN_PROGRESS, etc.)
Full Transcript
This visual execution shows how AWS CloudFormation updates and deletes stacks. First, you check if the stack exists. Then you submit an update with a new template. CloudFormation validates and applies the update, changing the stack status to UPDATE_IN_PROGRESS and then UPDATE_COMPLETE if successful. If the update fails, it rolls back to the previous state. After updating, you can delete the stack, which triggers deletion of all resources and removes the stack from CloudFormation. The stack status changes accordingly during these steps, helping track progress.

Practice

(1/5)
1. What is the primary purpose of the update-stack command in AWS CloudFormation?
easy
A. To create a new stack from a template
B. To safely change existing cloud resources managed by a stack
C. To delete all resources created by a stack
D. To list all stacks in your AWS account

Solution

  1. Step 1: Understand the role of update-stack

    The update-stack command is used to modify resources that are already managed by an existing CloudFormation stack.
  2. Step 2: Differentiate from other commands

    Unlike delete-stack which removes resources, update-stack changes them safely without deleting the stack.
  3. Final Answer:

    To safely change existing cloud resources managed by a stack -> Option B
  4. Quick Check:

    update-stack = change resources safely [OK]
Hint: Update-stack changes resources; delete-stack removes them [OK]
Common Mistakes:
  • Confusing update-stack with delete-stack
  • Thinking update-stack creates new stacks
  • Assuming update-stack lists stacks
2. Which AWS CLI command syntax correctly deletes a stack named MyAppStack?
easy
A. aws cloudformation delete-stack --stack-name MyAppStack
B. aws cloudformation update-stack --stack-name MyAppStack
C. aws cloudformation remove-stack --name MyAppStack
D. aws cloudformation destroy-stack --stack MyAppStack

Solution

  1. Step 1: Identify the correct delete command

    The correct AWS CLI command to delete a stack is delete-stack with the parameter --stack-name.
  2. 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.
  3. Final Answer:

    aws cloudformation delete-stack --stack-name MyAppStack -> Option A
  4. Quick Check:

    delete-stack + --stack-name = correct syntax [OK]
Hint: Delete stacks with 'delete-stack' and '--stack-name' [OK]
Common Mistakes:
  • Using update-stack instead of delete-stack
  • Wrong parameter names like --name or --stack
  • Using non-existent commands like remove-stack or destroy-stack
3. Given this AWS CLI command sequence:
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?
medium
A. The stack TestStack is updated with the new template, and its status is shown
B. The stack TestStack is deleted, and no status is returned
C. A new stack named TestStack is created, and its details are displayed
D. The command fails because update-stack cannot be followed by describe-stacks

Solution

  1. Step 1: Understand update-stack effect

    The update-stack command modifies the existing stack named TestStack using the provided template.
  2. Step 2: Describe-stacks shows current stack status

    The describe-stacks command retrieves details about TestStack, including its updated status.
  3. Final Answer:

    The stack TestStack is updated with the new template, and its status is shown -> Option A
  4. Quick Check:

    update-stack changes stack + describe-stacks shows status [OK]
Hint: Update then describe shows updated stack status [OK]
Common Mistakes:
  • Thinking update-stack deletes the stack
  • Assuming describe-stacks creates a new stack
  • Believing update-stack and describe-stacks cannot be used sequentially
4. You run 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?
medium
A. Ignore the error and rerun update-stack multiple times
B. Run delete-stack immediately to remove the stack
C. Change the stack name and try update-stack again
D. Wait for the current update to finish before running update-stack again

Solution

  1. Step 1: Understand stack states during update

    When a stack is in UPDATE_IN_PROGRESS, it means an update is already running and must complete before another update starts.
  2. 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.
  3. Final Answer:

    Wait for the current update to finish before running update-stack again -> Option D
  4. Quick Check:

    UPDATE_IN_PROGRESS means wait before next update [OK]
Hint: Wait for update to finish before next update [OK]
Common Mistakes:
  • Trying to delete stack during update
  • Renaming stack instead of waiting
  • Ignoring error and retrying immediately
5. You want to update a stack but also ensure that if the update fails, the stack rolls back to its previous state automatically. Which AWS CloudFormation option should you avoid using with update-stack to achieve this?
hard
A. --rollback-configuration
B. --no-rollback
C. --disable-rollback
D. --enable-rollback

Solution

  1. Step 1: Understand rollback behavior in update-stack

    By default, CloudFormation rolls back stack updates on failure. The --disable-rollback option disables this behavior.
  2. 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.
  3. Step 3: Analyze options

    --rollback-configuration is for configuring alarms, --enable-rollback and --no-rollback are not valid AWS CLI options.
  4. Final Answer:

    --disable-rollback disables rollback; omit it to keep rollback enabled -> Option C
  5. Quick Check:

    Omit --disable-rollback to keep rollback on failure [OK]
Hint: Do not use --disable-rollback to keep rollback active [OK]
Common Mistakes:
  • Using non-existent --enable-rollback option
  • Confusing disable-rollback disables rollback
  • Assuming rollback is off by default
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard