AWS::CloudFormation::Stack - AWS CloudFormation

AWS::CloudFormation::Stack

The AWS::CloudFormation::Stack resource nests a stack as a resource in a top-level template.

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 .

Important

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 more information, see CloudFormation stack updates.

Note

You must acknowledge IAM capabilities for nested stacks that contain IAM resources. Also, verify that you have cancel update stack permissions, which is required if an update rolls back. For more information about IAM and CloudFormation, see Controlling access with AWS Identity and Access Management.

Important

A subset of AWS::CloudFormation::Stack resource type properties listed below are available to customers using AWS 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 AWS 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 AWS 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" : {Key: Value, ...}, "ParentId" : 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: - String ChangeSetId: String CreationTime: String Description: String DisableRollback: Boolean EnableTerminationProtection: Boolean LastUpdateTime: String NotificationARNs: - String Outputs: - Output Parameters: Key: Value ParentId: 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

Properties

Capabilities

In some cases, you must explicitly acknowledge that your stack template contains certain capabilities in order for AWS CloudFormation to create the stack.

  • CAPABILITY_IAM and CAPABILITY_NAMED_IAM

    Some 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_IAM or CAPABILITY_NAMED_IAM capability.

    • 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, AWS CloudFormation returns an InsufficientCapabilities error.

    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 AWS CloudFormation Templates.

  • CAPABILITY_AUTO_EXPAND

    Some 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 AWS 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 AWS CloudFormation being notified.

    For more information, see Using AWS CloudFormation macros to perform custom processing on templates.

Required: No

Type: Array of String

Allowed values: CAPABILITY_IAM | CAPABILITY_NAMED_IAM | CAPABILITY_AUTO_EXPAND

Update requires: No interruption

ChangeSetId

The unique ID of the change set.

Required: No

Type: String

Pattern: arn:[-a-zA-Z0-9:/]*

Minimum: 1

Update 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: 1

Maximum: 1024

Update requires: No interruption

DisableRollback

Set to true to disable rollback of the stack if stack creation failed. You can specify either DisableRollback or OnFailure, but not both.

Default: false

Required: 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 Protecting a Stack 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: 5

Update 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 Ref function to pass a parameter value to a nested stack, comma-delimited list parameters must be of type String. In other words, you can't pass values that are of type CommaDelimitedList to nested stacks.

Conditional. 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--stacks created as resources for another stack--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 Embed stacks within other stacks using nested stacks in the AWS CloudFormation User Guide.

Required: No

Type: String

Update requires: Replacement

RoleARN

The Amazon Resource Name (ARN) of an AWS Identity and Access Management (IAM) role that AWS CloudFormation assumes to create the stack. AWS CloudFormation uses the role's credentials to make calls on your behalf. AWS CloudFormation always uses this role for all future operations on the stack. Provided that users have permission to operate on the stack, AWS 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, AWS CloudFormation uses the role that was previously associated with the stack. If no role is available, AWS CloudFormation uses a temporary session that's generated from your user credentials.

Required: No

Type: String

Minimum: 20

Maximum: 2048

Update requires: No interruption

RootId

For nested stacks--stacks created as resources for another stack--the stack ID of the top-level stack to which the nested stack ultimately belongs.

For more information, see Embed stacks within other stacks using 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 containing the stack policy body. For more information, go to Prevent Updates to Stack Resources in the AWS CloudFormation User Guide. You can specify either the StackPolicyBody or the StackPolicyURL parameter, but not both.

Required: No

Type: Json

Minimum: 1

Maximum: 16384

Update requires: No interruption

StackPolicyURL

Location of a file containing 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 StackPolicyBody or the StackPolicyURL parameter, but not both.

Required: No

Type: String

Minimum: 1

Maximum: 1350

Update 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_COMPLETE

Update requires: Replacement

StackStatusReason

Success/failure message associated with the stack status.

Required: No

Type: String

Update requires: No interruption

Tags

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: 50

Update requires: No interruption

TemplateBody

Structure containing the template body with a minimum length of 1 byte and a maximum length of 51,200 bytes. For more information, go to Template anatomy in the AWS CloudFormation User Guide.

Conditional: You must specify either the TemplateBody or the TemplateURL parameter, but not both.

Required: No

Type: Json

Minimum: 1

Update requires: No interruption

TemplateURL

Location of file containing the template body. The URL must point to a template (max size: 460,800 bytes) that's located in an Amazon S3 bucket. For more information, see Template anatomy.

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: 1

Maximum: 1024

Update requires: No interruption

TimeoutInMinutes

The length of time, in minutes, that CloudFormation waits for the nested stack to reach the CREATE_COMPLETE state. The default is no timeout. When CloudFormation detects that the nested stack has reached the CREATE_COMPLETE state, it marks the nested stack resource as CREATE_COMPLETE in the parent stack and resumes creating the parent stack. If the timeout period expires before the nested stack reaches CREATE_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: 1

Update 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-east-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 ID of the change set.

CreationTime

Returns The time at which 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--stacks created as resources for another stack--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.

For more information, see Working with Nested Stacks in the AWS CloudFormation User Guide.

RootId

For nested stacks--stacks created as resources for another stack--returns the stack ID of the top-level stack to which the nested stack ultimately belongs.

For more information, see Working with Nested Stacks in the AWS CloudFormation User Guide.

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 EC2ChooseAMI.template 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/cloudformation-templates-us-east-2/EC2ChooseAMI.template", "Parameters" : { "InstanceType" : "t1.micro", "KeyName" : "mykey" } } } } }

YAML

AWSTemplateFormatVersion: '2010-09-09' Resources: myStackWithParams: Type: AWS::CloudFormation::Stack Properties: TemplateURL: https://s3.amazonaws.com/cloudformation-templates-us-east-2/EC2ChooseAMI.template Parameters: InstanceType: t1.micro KeyName: mykey

See also