Modifying a stack template - Amazon CloudFormation
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Modifying a stack template

If you want to modify resources and properties that are declared in a stack template, you must modify the stack's template. To ensure that you update only the resources that you intend to update, use the template for the existing stack as a starting point and make your updates to that template. If you are managing your template in a source control system, use a copy of that template as a starting point. Otherwise, you can get a copy of a stack template from Amazon CloudFormation.

If you want to modify just the parameters or settings of a stack (like a stack's Amazon SNS topic), you can reuse the existing stack template. You don't need to get a copy of the stack template or make modifications to the stack template.

Note

If your template includes an unsupported change, Amazon CloudFormation returns a message saying that the change isn't permitted. This message might occur asynchronously, however, because resources are created and updated by Amazon CloudFormation in a non-deterministic order by default.

Update a stack's template (console)

  1. On the Stacks page of the Amazon CloudFormation console, click the name of the stack that you want to update.

  2. In the stack details pane for the selected stack, select the Template pane, and then click View in Designer.

    Amazon CloudFormation opens a copy of the stack's template in Amazon CloudFormation Designer.

  3. Modify the template.

    You can use the Amazon CloudFormation Designer drag-and-drop interface or the integrated JSON and YAML editor to modify the template. For more information about using Amazon CloudFormation Designer, see What is Amazon CloudFormation Designer?.

    Modify only the resources that you want to update. Use the same values as the current stack configuration for resources and properties that you aren't updating. You can modify the template by completing any of the following actions:

    • Add new resources, or remove existing resources.

      For most resources, changing the logical name of a resource is equivalent to deleting that resource and replacing it with a new one. Any other resources that depend on the renamed resource also need to be updated and might cause them to be replaced. Other resources require you to update a property (not just the logical name) in order to initiate an update.

    • Add, modify, or delete properties of existing resources.

      Consult the Amazon Resource Types Reference for information about the effects of updating particular resource properties. For each property, the effects of an update will be one of the following:

    • Add, modify, or delete attributes for resources (Metadata, DependsOn, CreationPolicy, UpdatePolicy, and DeletionPolicy).

      Important

      You can't update the CreationPolicy or UpdatePolicy attribute by itself. You can update them only when you include changes that add, modify, or delete resources. For example, you can add or modify a metadata attribute of a resource.

    • Add, modify, or delete parameter declarations. However, you can't add, modify, or delete a parameter that's used by a resource that doesn't support updates.

    • Add, modify, or delete mapping declarations.

      Important

      If the values in a mapping aren't being used by your stack, you can't update the mapping by itself. You need to include changes that add, modify, or delete resources. For example, you can add or modify a metadata attribute of a resource. If you update a mapping value that your stack is using, you don't need to make any other changes to initiate an update.

    • Add, modify, or delete condition declarations.

      Important

      You can't update conditions by themselves. You can update conditions only when you include changes that add, modify, or delete resources. For example, you can add or modify a metadata attribute of a resource.

    • Add, modify, or delete output value declarations.

    Some resources or properties may have constraints on property values or changes to those values. For example, changes to the AllocatedStorage property of an AWS::RDS::DBInstance resource must be greater than the current setting. If the value specified for the update doesn't meet those constraints, the update for that resource fails. For the specific constraints on AllocatedStorage changes, see ModifyDBInstance.

    Updates to a resource can affect the properties of other resources. If you used the Ref function or the Fn::GetAtt function to specify an attribute from an updated resource as part of a property value in another resource in the template, Amazon CloudFormation also updates the resource that contains the reference to the property that has changed. For example, if you updated the MasterUsername property of an AWS::RDS::DBInstance resource and you had an AWS::AutoScaling::LaunchConfiguration resource that had a UserData property that contained a reference to the DB instance name using the Ref function, Amazon CloudFormation would recreate the DB instance with a new name and also update the LaunchConfiguration resource.

  4. To check for syntax errors in your template, from the Amazon CloudFormation Designer toolbar, choose Validate template ( ).

    View and fix any errors in the Messages pane, and then validate the template again. If you don't see any errors, your template is syntactically valid.

  5. From the Amazon CloudFormation Designer toolbar, choose the File menu ( ) and then Save to save the template in an S3 bucket or locally.

  6. Use your modified template to update your stack directly or update your stack using a change set.

Get and update a template for a stack (CLI)

  1. To get the template for the stack you want to update, use the command aws cloudformation get-template.

  2. Copy the template, paste it into a text file, modify it, and save it. Copy only the template. The command encloses the template in quotation marks, but don't copy the quotation marks surrounding the template. The template itself starts with an open brace and ends with the final close brace. Specify changes to the stack's resources in this file.

  3. Use your modified template to update your stack directly or update your stack using a change set.