Updating CloudFormation Stacks - Tutorial

Welcome to this tutorial on updating CloudFormation stacks in AWS CloudFormation. When working with infrastructure as code, it's essential to have the ability to make changes and updates to your existing stacks. CloudFormation provides a straightforward process for updating stacks while ensuring minimal disruption to your resources.

Example of Updating a Stack

Let's consider a simple example where you have an existing CloudFormation stack that deploys an Amazon EC2 instance. Now, you want to update the stack by modifying the instance type.

aws cloudformation update-stack --stack-name MyStack --template-body file://my-updated-template.yml

In the above example, we use the AWS CLI command update-stack to initiate the stack update. The command specifies the stack name and the updated template file containing the modified instance type.

Steps to Update CloudFormation Stacks

  1. Identify the stack you want to update.
  2. Make the necessary changes to the CloudFormation template file.
  3. Ensure the updated template file is accessible, either locally or through an S3 bucket.
  4. Use the AWS CLI, AWS Management Console, or AWS SDKs to initiate the stack update.
  5. Monitor the stack update progress using CloudFormation events and stack status.
  6. Validate the updated stack to ensure the changes were applied successfully.

Common Mistakes when Updating Stacks

  • Forgetting to specify the updated template file during the update process.
  • Modifying the existing stack resources without updating the template.
  • Missing required permissions to update CloudFormation stacks.
  • Not considering potential resource interruptions during the stack update.
  • Ignoring warnings or errors reported during the update process.

Frequently Asked Questions (FAQs)

1. Can I update a CloudFormation stack that is in the DELETE_FAILED state?

No, you cannot update a stack that is in the DELETE_FAILED state. You must first delete the stack or resolve the deletion failure before initiating an update.

2. What happens to the existing resources when updating a stack?

When updating a stack, CloudFormation handles the changes intelligently. It creates new resources, modifies existing ones, and deletes obsolete resources based on the updates defined in the template.

3. How can I roll back a failed stack update?

If a stack update fails, CloudFormation can automatically roll back the changes, returning the stack to its previous state. You can also manually trigger a rollback using the AWS CLI or the AWS Management Console.

4. Can I update stack parameters during an update?

Yes, you can update stack parameters during a stack update. However, not all parameter modifications are supported, and some may require specific update behaviors defined in the template.

5. Can I view the changes before updating the stack?

Yes, you can generate a change set that shows the differences between the current stack and the proposed changes. This allows you to review and approve the modifications before applying them.


Updating CloudFormation stacks is a crucial aspect of managing your infrastructure as code. By following the steps outlined in this tutorial, you can safely and efficiently update your CloudFormation stacks, enabling you to adapt your infrastructure to changing requirements.