There are more AWS SDK examples available in the AWS Doc SDK Examples
Use UpdateStack with a CLI
The following code examples show how to use UpdateStack.
- CLI
-
- AWS CLI
-
To update AWS CloudFormation stacks
The following
update-stackcommand updates the template and input parameters for themystackstack:aws cloudformation update-stack --stack-namemystack--template-urlhttps://s3.amazonaws.com/sample/updated.template--parametersParameterKey=KeyPairName,ParameterValue=SampleKeyPairParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,SampleSubnetID2The following
update-stackcommand updates just theSubnetIDsparameter value for themystackstack. If you don't specify a parameter value, the default value that is specified in the template is used:aws cloudformation update-stack --stack-namemystack--template-urlhttps://s3.amazonaws.com/sample/updated.template--parametersParameterKey=KeyPairName,UsePreviousValue=trueParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,UpdatedSampleSubnetID2The following
update-stackcommand adds two stack notification topics to themystackstack:aws cloudformation update-stack --stack-namemystack--use-previous-template --notification-arns"arn:aws:sns:use-east-1:123456789012:mytopic1""arn:aws:sns:us-east-1:123456789012:mytopic2"For more information, see AWS CloudFormation stack updates in the AWS CloudFormation User Guide.
-
For API details, see UpdateStack
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: Updates the stack 'myStack' with the specified template and customization parameters. 'PK1' represents the name of a parameter declared in the template and 'PV1' represents its value. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'.
Update-CFNStack -StackName "myStack" ` -TemplateBody "{Template Content Here}" ` -Parameter @{ ParameterKey="PK1"; ParameterValue="PV1" }Example 2: Updates the stack 'myStack' with the specified template and customization parameters. 'PK1' and 'PK2' represent the names of parameters declared in the template, 'PV1' and 'PV2' represents their requested values. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'.
Update-CFNStack -StackName "myStack" ` -TemplateBody "{Template Content Here}" ` -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } )Example 3: Updates the stack 'myStack' with the specified template and customization parameters. 'PK1' represents the name of a parameter declared in the template and 'PV2' represents its value. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'.
Update-CFNStack -StackName "myStack" -TemplateBody "{Template Content Here}" -Parameters @{ ParameterKey="PK1"; ParameterValue="PV1" }Example 4: Updates the stack 'myStack' with the specified template, obtained from Amazon S3, and customization parameters. 'PK1' and 'PK2' represent the names of parameters declared in the template, 'PV1' and 'PV2' represents their requested values. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'.
Update-CFNStack -StackName "myStack" ` -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template ` -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } )Example 5: Updates the stack 'myStack', which is assumed in this example to contain IAM resources, with the specified template, obtained from Amazon S3, and customization parameters. 'PK1' and 'PK2' represent the names of parameters declared in the template, 'PV1' and 'PV2' represents their requested values. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'. Stacks containing IAM resources require you to specify the -Capabilities "CAPABILITY_IAM" parameter otherwise the update will fail with an 'InsufficientCapabilities' error.
Update-CFNStack -StackName "myStack" ` -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template ` -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } ) ` -Capabilities "CAPABILITY_IAM"-
For API details, see UpdateStack in AWS Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
Example 1: Updates the stack 'myStack' with the specified template and customization parameters. 'PK1' represents the name of a parameter declared in the template and 'PV1' represents its value. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'.
Update-CFNStack -StackName "myStack" ` -TemplateBody "{Template Content Here}" ` -Parameter @{ ParameterKey="PK1"; ParameterValue="PV1" }Example 2: Updates the stack 'myStack' with the specified template and customization parameters. 'PK1' and 'PK2' represent the names of parameters declared in the template, 'PV1' and 'PV2' represents their requested values. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'.
Update-CFNStack -StackName "myStack" ` -TemplateBody "{Template Content Here}" ` -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } )Example 3: Updates the stack 'myStack' with the specified template and customization parameters. 'PK1' represents the name of a parameter declared in the template and 'PV2' represents its value. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'.
Update-CFNStack -StackName "myStack" -TemplateBody "{Template Content Here}" -Parameters @{ ParameterKey="PK1"; ParameterValue="PV1" }Example 4: Updates the stack 'myStack' with the specified template, obtained from Amazon S3, and customization parameters. 'PK1' and 'PK2' represent the names of parameters declared in the template, 'PV1' and 'PV2' represents their requested values. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'.
Update-CFNStack -StackName "myStack" ` -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template ` -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } )Example 5: Updates the stack 'myStack', which is assumed in this example to contain IAM resources, with the specified template, obtained from Amazon S3, and customization parameters. 'PK1' and 'PK2' represent the names of parameters declared in the template, 'PV1' and 'PV2' represents their requested values. The customization parameters can also be specified using 'Key' and 'Value' instead of 'ParameterKey' and 'ParameterValue'. Stacks containing IAM resources require you to specify the -Capabilities "CAPABILITY_IAM" parameter otherwise the update will fail with an 'InsufficientCapabilities' error.
Update-CFNStack -StackName "myStack" ` -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template ` -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } ) ` -Capabilities "CAPABILITY_IAM"-
For API details, see UpdateStack in AWS Tools for PowerShell Cmdlet Reference (V5).
-