This is the new AWS CloudFormation Template Reference Guide. Please update your bookmarks and links. For help getting started with CloudFormation, see the AWS CloudFormation User Guide.
AWS::CloudFormation::Stack
The AWS::CloudFormation::Stack resource nests a stack as a resource in a
top-level template. For more information, see Nested
stacks in the AWS CloudFormation User Guide.
You can add output values from a nested stack within the containing template. You use
the GetAtt function with the nested stack's logical name and the name of the
output value in the nested stack in the format
Outputs.NestedStackOutputName.
We strongly recommend that updates to nested stacks are run from the parent stack.
When you apply template changes to update a top-level stack, CloudFormation updates the top-level stack and initiates an update to its nested stacks. CloudFormation updates the resources of modified nested stacks, but doesn't update the resources of unmodified nested stacks.
For stacks that contain IAM resources, you must acknowledge IAM capabilities. Also, make sure that you have cancel update stack permissions, which are required if an update rolls back. For more information about IAM and CloudFormation, see Controlling access with AWS Identity and Access Management in the AWS CloudFormation User Guide.
Note
A subset of AWS::CloudFormation::Stack resource type properties
listed below are available to customers using CloudFormation, AWS CDK, and AWS Cloud Control API to configure.
-
NotificationARNs -
Parameters -
Tags -
TemplateURL -
TimeoutInMinutes
These properties can be configured only when using AWS Cloud Control API. This is because the below properties are set by the parent stack, and thus cannot be configured using CloudFormation or AWS CDK but only AWS Cloud Control API.
-
Capabilities -
Description -
DisableRollback -
EnableTerminationProtection -
RoleARN -
StackName -
StackPolicyBody -
StackPolicyURL -
StackStatusReason -
TemplateBody
Customers that configure AWS::CloudFormation::Stack using CloudFormation and AWS CDK can do so for nesting a CloudFormation stack as a resource in their top-level template.
These read-only properties can be accessed only when using AWS Cloud Control API.
-
ChangeSetId -
CreationTime -
LastUpdateTime -
Outputs -
ParentId -
RootId -
StackId -
StackStatus
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::CloudFormation::Stack", "Properties" : { "Capabilities" :[ String, ... ], "ChangeSetId" :String, "CreationTime" :String, "Description" :String, "DisableRollback" :Boolean, "EnableTerminationProtection" :Boolean, "LastUpdateTime" :String, "NotificationARNs" :[ String, ... ], "Outputs" :[ Output, ... ], "Parameters" :{, "ParentId" :Key:Value, ...}String, "RoleARN" :String, "RootId" :String, "StackId" :String, "StackName" :String, "StackPolicyBody" :Json, "StackPolicyURL" :String, "StackStatus" :String, "StackStatusReason" :String, "Tags" :[ Tag, ... ], "TemplateBody" :Json, "TemplateURL" :String, "TimeoutInMinutes" :Integer} }
YAML
Type: AWS::CloudFormation::Stack Properties: Capabilities:- StringChangeSetId:StringCreationTime:StringDescription:StringDisableRollback:BooleanEnableTerminationProtection:BooleanLastUpdateTime:StringNotificationARNs:- StringOutputs:- OutputParameters:ParentId:Key:ValueStringRoleARN:StringRootId:StringStackId:StringStackName:StringStackPolicyBody:JsonStackPolicyURL:StringStackStatus:StringStackStatusReason:StringTags:- TagTemplateBody:JsonTemplateURL:StringTimeoutInMinutes:Integer
Properties
Capabilities-
In some cases, you must explicitly acknowledge that your stack template contains certain capabilities in order for CloudFormation to create the stack.
-
CAPABILITY_IAMandCAPABILITY_NAMED_IAMSome stack templates might include resources that can affect permissions in your AWS account; for example, by creating new AWS Identity and Access Management (IAM) users. For those stacks, you must explicitly acknowledge this by specifying one of these capabilities.
The following IAM resources require you to specify either the
CAPABILITY_IAMorCAPABILITY_NAMED_IAMcapability.-
If you have IAM resources, you can specify either capability.
-
If you have IAM resources with custom names, you must specify
CAPABILITY_NAMED_IAM. -
If you don't specify either of these capabilities, CloudFormation returns an
InsufficientCapabilitieserror.
If your stack template contains these resources, we recommend that you review all permissions associated with them and edit their permissions if necessary.
For more information, see Acknowledging IAM resources in CloudFormation templates in the AWS CloudFormation User Guide.
-
-
CAPABILITY_AUTO_EXPANDSome template contain macros. Macros perform custom processing on templates; this can include simple actions like find-and-replace operations, all the way to extensive transformations of entire templates. Because of this, users typically create a change set from the processed template, so that they can review the changes resulting from the macros before actually creating the stack. If your stack template contains one or more macros, and you choose to create a stack directly from the processed template, without first reviewing the resulting changes in a change set, you must acknowledge this capability. This includes the AWS::Include and AWS::Serverless transforms, which are macros hosted by CloudFormation.
If you want to create a stack from a stack template that contains macros and nested stacks, you must create the stack directly from the template using this capability.
Important
You should only create stacks directly from a stack template that contains macros if you know what processing the macro performs.
Each macro relies on an underlying Lambda service function for processing stack templates. Be aware that the Lambda function owner can update the function operation without CloudFormation being notified.
For more information, see Perform custom processing on CloudFormation templates with template macros in the AWS CloudFormation User Guide.
Required: No
Type: Array of String
Allowed values:
CAPABILITY_IAM | CAPABILITY_NAMED_IAM | CAPABILITY_AUTO_EXPANDUpdate requires: No interruption
-
ChangeSetId-
The unique ID of the change set.
Required: No
Type: String
Pattern:
arn:[-a-zA-Z0-9:/]*Minimum:
1Update requires: Replacement
CreationTime-
The time at which the stack was created.
Required: No
Type: String
Update requires: Replacement
Description-
A user-defined description associated with the stack.
Required: No
Type: String
Minimum:
1Maximum:
1024Update requires: No interruption
DisableRollback-
Set to
trueto disable rollback of the stack if stack creation failed. You can specify eitherDisableRollbackorOnFailure, but not both.Default:
falseRequired: No
Type: Boolean
Update requires: No interruption
EnableTerminationProtection-
Whether to enable termination protection on the specified stack. If a user attempts to delete a stack with termination protection enabled, the operation fails and the stack remains unchanged. For more information, see Protect CloudFormation stacks from being deleted in the AWS CloudFormation User Guide. Termination protection is deactivated on stacks by default.
For nested stacks, termination protection is set on the root stack and can't be changed directly on the nested stack.
Required: No
Type: Boolean
Update requires: No interruption
LastUpdateTime-
The time the stack was last updated. This field will only be returned if the stack has been updated at least once.
Required: No
Type: String
Update requires: Replacement
NotificationARNs-
The Amazon SNS topic ARNs to publish stack related events. You can find your Amazon SNS topic ARNs using the Amazon SNS console or your Command Line Interface (CLI).
Required: No
Type: Array of String
Maximum:
5Update requires: No interruption
Outputs-
A list of output structures.
Required: No
Type: Array of Output
Update requires: Replacement
Parameters-
The set value pairs that represent the parameters passed to CloudFormation when this nested stack is created. Each parameter has a name corresponding to a parameter defined in the embedded template and a value representing the value that you want to set for the parameter.
Note
If you use the
Reffunction to pass a parameter value to a nested stack, comma-delimited list parameters must be of typeString. In other words, you can't pass values that are of typeCommaDelimitedListto nested stacks.Required if the nested stack requires input parameters.
Whether an update causes interruptions depends on the resources that are being updated. An update never causes a nested stack to be replaced.
Required: Conditional
Type: Object of String
Pattern:
[a-zA-Z0-9]+Update requires: No interruption
ParentId-
For nested stacks, the stack ID of the direct parent of this stack. For the first level of nested stacks, the root stack is also the parent stack.
For more information, see Nested stacks in the AWS CloudFormation User Guide.
Required: No
Type: String
Update requires: Replacement
RoleARN-
The Amazon Resource Name (ARN) of an IAM role that CloudFormation assumes to create the stack. CloudFormation uses the role's credentials to make calls on your behalf. CloudFormation always uses this role for all future operations on the stack. Provided that users have permission to operate on the stack, CloudFormation uses this role even if the users don't have permission to pass it. Ensure that the role grants least privilege.
If you don't specify a value, CloudFormation uses the role that was previously associated with the stack. If no role is available, CloudFormation uses a temporary session that's generated from your user credentials.
Required: No
Type: String
Minimum:
20Maximum:
2048Update requires: No interruption
RootId-
For nested stacks, the stack ID of the top-level stack to which the nested stack ultimately belongs.
For more information, see Nested stacks in the AWS CloudFormation User Guide.
Required: No
Type: String
Update requires: Replacement
StackId-
Unique identifier of the stack.
Required: No
Type: String
Update requires: Replacement
StackName-
The name that's associated with the stack. The name must be unique in the Region in which you are creating the stack.
Note
A stack name can contain only alphanumeric characters (case sensitive) and hyphens. It must start with an alphabetical character and can't be longer than 128 characters.
Required: Yes
Type: String
Update requires: Replacement
StackPolicyBody-
Structure that contains the stack policy body. For more information, see Prevent updates to stack resources in the AWS CloudFormation User Guide. You can specify either the
StackPolicyBodyor theStackPolicyURLparameter, but not both.Required: No
Type: Json
Minimum:
1Maximum:
16384Update requires: No interruption
StackPolicyURL-
Location of a file that contains the stack policy. The URL must point to a policy (maximum size: 16 KB) located in an S3 bucket in the same Region as the stack. You can specify either the
StackPolicyBodyor theStackPolicyURLparameter, but not both.Required: No
Type: String
Minimum:
1Maximum:
5120Update requires: No interruption
StackStatus-
Current status of the stack.
Required: No
Type: String
Allowed values:
CREATE_IN_PROGRESS | CREATE_FAILED | CREATE_COMPLETE | ROLLBACK_IN_PROGRESS | ROLLBACK_FAILED | ROLLBACK_COMPLETE | DELETE_IN_PROGRESS | DELETE_FAILED | DELETE_COMPLETE | UPDATE_IN_PROGRESS | UPDATE_COMPLETE_CLEANUP_IN_PROGRESS | UPDATE_COMPLETE | UPDATE_FAILED | UPDATE_ROLLBACK_IN_PROGRESS | UPDATE_ROLLBACK_FAILED | UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS | UPDATE_ROLLBACK_COMPLETE | REVIEW_IN_PROGRESS | IMPORT_IN_PROGRESS | IMPORT_COMPLETE | IMPORT_ROLLBACK_IN_PROGRESS | IMPORT_ROLLBACK_FAILED | IMPORT_ROLLBACK_COMPLETEUpdate requires: Replacement
StackStatusReason-
Success/failure message associated with the stack status.
Required: No
Type: String
Update requires: No interruption
-
Key-value pairs to associate with this stack. CloudFormation also propagates these tags to the resources created in the stack. A maximum number of 50 tags can be specified.
Required: No
Type: Array of Tag
Maximum:
50Update requires: No interruption
TemplateBody-
Structure that contains the template body with a minimum length of 1 byte and a maximum length of 51,200 bytes.
Conditional: You must specify either the
TemplateBodyor theTemplateURLparameter, but not both.Required: No
Type: Json
Minimum:
1Update requires: No interruption
TemplateURL-
The URL of a file that contains the template body. The URL must point to a template (max size: 1 MB) that's located in an Amazon S3 bucket. The location for an Amazon S3 bucket must start with
https://.Whether an update causes interruptions depends on the resources that are being updated. An update never causes a nested stack to be replaced.
Required: No
Type: String
Minimum:
1Maximum:
1024Update requires: No interruption
TimeoutInMinutes-
The length of time, in minutes, that CloudFormation waits for the nested stack to reach the
CREATE_COMPLETEstate. The default is no timeout. When CloudFormation detects that the nested stack has reached theCREATE_COMPLETEstate, it marks the nested stack resource asCREATE_COMPLETEin the parent stack and resumes creating the parent stack. If the timeout period expires before the nested stack reachesCREATE_COMPLETE, CloudFormation marks the nested stack as failed and rolls back both the nested stack and parent stack.Updates aren't supported.
Required: No
Type: Integer
Minimum:
1Update requires: No interruption
Return values
Ref
When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the stack ID. For example:
arn:aws:cloudformation:us-west-2:123456789012:stack/mystack-mynestedstack-sggfrhxhum7w/f449b250-b969-11e0-a185-5081d0136786
For more information about using the Ref function, see Ref.
Fn::GetAtt
The Fn::GetAtt intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.
For more information about using the Fn::GetAtt intrinsic function, see Fn::GetAtt.
ChangeSetId-
Returns the unique identifier of the change set.
CreationTime-
Returns the time the stack was created.
LastUpdateTime-
Returns the time the stack was last updated. This will only be returned if the stack has been updated at least once.
Outputs-
Returns a list of output structures.
ParentId-
For nested stacks, returns the stack ID of the direct parent of this stack. For the first level of nested stacks, the root stack is also the parent stack.
RootId-
For nested stacks, returns the stack ID of the top-level stack to which the nested stack ultimately belongs.
StackId-
Returns the unique identifier of the stack.
StackStatus-
Returns a success or failure message associated with the stack status.
Examples
Specify stack parameters
The sample template EC2ChooseAMI.template contains the following Parameters section:
JSON
{ "Parameters": { "InstanceType": { "Type": "String", "Default": "m1.small", "Description": "EC2 instance type, e.g. m1.small, m1.large, etc." }, "WebServerPort": { "Type": "String", "Default": "80", "Description": "TCP/IP port of the web server" }, "KeyName": { "Type": "String", "Description": "Name of an existing EC2 KeyPair to enable SSH access to the web server" } } }
YAML
Parameters: InstanceType: Type: String Default: m1.small Description: 'EC2 instance type, e.g. m1.small, m1.large, etc.' WebServerPort: Type: String Default: '80' Description: TCP/IP port of the web server KeyName: Type: String Description: Name of an existing EC2 KeyPair to enable SSH access to the web server
Nested stack
You could use the following template to embed a stack
(myStackWithParams) using the my-template.yaml and
use the Parameters property in the
AWS::CloudFormation::Stack resource to specify an
InstanceType and KeyName.
JSON
{ "AWSTemplateFormatVersion" : "2010-09-09", "Resources" : { "myStackWithParams" : { "Type" : "AWS::CloudFormation::Stack", "Properties" : { "TemplateURL" : "https://s3.amazonaws.com/amzn-s3-demo-bucket/my-template.yaml", "Parameters" : { "InstanceType" : "t1.micro", "KeyName" : "mykey" } } } } }
YAML
AWSTemplateFormatVersion: '2010-09-09' Resources: myStackWithParams: Type: AWS::CloudFormation::Stack Properties: TemplateURL: https://s3.amazonaws.com/amzn-s3-demo-bucket/MyTemplate.yaml Parameters: InstanceType: t1.micro KeyName: mykey
See also
-
For sample template snippets, see CloudFormation template snippets in the AWS CloudFormation User Guide.
-
If you have nested stacks that are stuck in an in-progress operation, see Troubleshooting Errors in Troubleshooting AWS CloudFormation in the AWS CloudFormation User Guide.