Examples of CloudFormation stack operation commands for the AWS CLI and PowerShell
The following command line examples demonstrate how to perform individual CloudFormation actions with the AWS CLI and PowerShell. These examples include only the most commonly used actions. For a complete list, see cloudformation in the AWS CLI Command Reference.
The examples in this guide use the convention of a backslash (\) to indicate that a long command line continues on the next line.
Topics
Cancel a stack update
Use the cancel-update-stack command command to cancel a stack update. For more information, see Cancel a stack update.
Continue rolling back an update
Use the continue-update-rollback command to continue rolling back an update. For more information, see Continue rolling back an update.
Create a stack
Use the create-stack command to create a stack. You must provide the stack name, the location of a valid template, and any input parameters. The parameter key names are case sensitive. If you mistype a parameter key name, CloudFormation doesn't create the stack and reports that the template doesn't contain that parameter.
The following examples show how to create a new stack with the specified name, template, and input parameters.
Note
You can use the AWS CLI --template-url option to specify a template
file location in Amazon S3 or AWS Systems Manager.
For Amazon S3, the URL must begin with https://. S3 static website URLs are not supported.
--template-url https://s3.region-code.amazonaws.com/bucket-name/template-nameFor AWS Systems Manager, use the following format:
--template-url "ssm-doc://arn:aws:ssm:region-code:account-id:document/document-name"Create a stack that includes transforms
Use the deploy
command to create a stack that includes transforms. When you create a stack from a
template that includes transforms, you must use a change set. The deploy
command combines two steps (creating a change set and executing it) into a single
command.
Delete a stack
Use the delete-stack command to delete a stack. For more information, see Delete a stack.
If the deletion fails and returns a DELETE_FAILED state, you can choose
to delete the stack by force using the --deletion-mode option. These are
the following values that can be used with deletion-mode:
-
STANDARD: Deletes the stack normally. This is the default deletion mode. -
FORCE_DELETE_STACK: Deletes the stack and skips all resources that are failing to delete.
After using FORCE_DELETE_STACK, you can use the
list-stack-resources command to list the resources that were skipped
during the stack deletion process. The retained resources will show a DELETE_SKIPPED
status. For more information, see List stack resources.
Describe stack events
Use the describe-stack-events command to describe stack events. For more information, see Monitor stack progress.
Describe a stack resource
Describe stack resources
Describe stacks
By default, the describe-stacks command returns parameter values. To
prevent sensitive parameter values such as passwords from being returned, include a
NoEcho property set to TRUE in your CloudFormation
templates.
Important
Using the NoEcho attribute does not mask any information stored in the following:
-
The
Metadatatemplate section. CloudFormation does not transform, modify, or redact any information you include in theMetadatasection. For more information, see Metadata. -
The
Outputstemplate section. For more information, see Outputs. -
The
Metadataattribute of a resource definition. For more information, seeMetadataattribute.
We strongly recommend you do not use these mechanisms to include sensitive information, such as passwords or secrets.
Important
Rather than embedding sensitive information directly in your CloudFormation templates, we recommend you use dynamic parameters in the stack template to reference sensitive information that is stored and managed outside of CloudFormation, such as in the AWS Systems Manager Parameter Store or AWS Secrets Manager.
For more information, see the Do not embed credentials in your templates best practice.
Get a template
List stack resources
List stacks
Use the list-stacks command to list stacks. To list only stacks
with the specified status codes, include the --stack-status-filter option.
You can specify one or more stack status codes for the
--stack-status-filter option. For more information, see Stack status
codes.
Update a stack
Use the update-stack command to directly update a stack. You specify the stack, and parameter values and capabilities that you want to update, and, if you want use an updated template, the name of the template. For more information, see Update stacks directly.
Note
To remove all notifications, specify for [] for the
--notification-arns option.
Validate your template
Use the validate-template command to check your template file for syntax errors.
During validation, CloudFormation first checks if the template is valid JSON. If it isn't, CloudFormation checks if the template is valid YAML. If both checks fail, CloudFormation returns a template validation error.
The following is an example response that produces a validation error.
{
"ResponseMetadata": {
"RequestId": "4ae33ec0-1988-11e3-818b-e15a6df955cd"
},
"Errors": [
{
"Message": "Template format error: JSON not well-formed. (line 11, column 8)",
"Code": "ValidationError",
"Type": "Sender"
}
],
"Capabilities": [],
"Parameters": []
}
A client error (ValidationError) occurred: Template format error: JSON not well-formed. (line 11, column 8)
Note
The validate-template command is designed to check only the syntax of
your template. It does not ensure that the property values that you have specified
for a resource are valid for that resource. Nor does it determine the number of
resources that will exist when the stack is created.
To check the operational validity, you need to attempt to create the stack. There is no sandbox or test area for CloudFormation stacks, so you are charged for the resources you create during testing.
Example availability
Can't find what you need? Request a new example by using the Provide feedback link at the bottom of this page.