AWS::CloudFormation::Stack
AWS::CloudFormation::Stack
类型在顶层模板中将堆栈作为资源进行嵌套。
您可以从该包含模板内的一个嵌套堆栈来添加输出值。您可以将 GetAtt 函数与该嵌套堆栈的逻辑名称以及嵌套堆栈中 Outputs.NestedStackOutputName
格式的输出值名称结合使用。
我们强烈建议您从父堆栈运行对嵌套堆栈的更新。
当您应用模板更改来更新顶级堆栈时,CloudFormation 会更新顶级堆栈,并启动对其嵌套堆栈的更新。CloudFormation 更新已修改嵌套堆栈的资源,但不更新未修改嵌套堆栈的资源。有关更多信息,请参阅 CloudFormation 堆栈更新。
您必须确认包含 IAM 资源的嵌套堆栈的 IAM 功能。另外还要确认您拥有取消更新堆栈权限,发生更新回滚时需要有此权限。有关 IAM 和 CloudFormation 的更多信息,请参阅使用 AWS Identity and Access Management 控制访问权限。
语法
要在 AWS CloudFormation 模板中声明此实体,请使用以下语法:
JSON
{ "Type" : "AWS::CloudFormation::Stack", "Properties" : { "NotificationARNs" :
[ String, ... ]
, "Parameters" :{
, "Tags" :Key
:Value
, ...}[ Tag, ... ]
, "TemplateURL" :String
, "TimeoutInMinutes" :Integer
} }
YAML
Type: AWS::CloudFormation::Stack Properties: NotificationARNs:
- String
Parameters:Tags:
Key
:Value
- Tag
TemplateURL:String
TimeoutInMinutes:Integer
属性
NotificationARNs
-
用于发布堆栈相关事件的 Simple Notification Service (SNS) 主题 ARN。您可以使用 SNS 控制台或命令行界面 (CLI) 查找 SNS 主题 ARN。
必需:否
类型:字符串列表
最高:
5
Update requires: No interruption
Parameters
-
一组值对,表示在创建此嵌套堆栈时传递给 CloudFormation 的参数。每个参数都具有对应于该嵌入式模板中定义的参数的名称,以及表示要为该参数设置的值。
注意 如果您使用
Ref
函数将参数值传递到嵌套堆栈,则逗号分隔列表参数必须属于String
类型。换言之,您不能将类型为CommaDelimitedList
的值传递给嵌套堆栈。这是有条件的。如果嵌套堆栈需要输入参数,则必需。
更新是否导致中断取决于所更新的资源。更新绝不会导致替换嵌套堆栈。
必需:条件
类型:字符串的映射
Update requires: No interruption
Tags
-
与此堆栈关联的键值对。AWS CloudFormation 还可以将这些标签传播到堆栈中创建的资源。最多可以指定 50 个标签.
必需:否
类型:Tag 的列表
最高:
50
Update requires: No interruption
TemplateURL
-
包含模板正文的文件的位置。URL 必须指向一个位于 Amazon S3 存储桶中的模板(最大大小:460800 字节)。有关更多信息,请参阅模板剖析。
更新是否导致中断取决于所更新的资源。更新绝不会导致替换嵌套堆栈。
必需:是
类型:字符串
最低:
1
最高:
1024
Update requires: No interruption
TimeoutInMinutes
-
CloudFormation 等待嵌套堆栈达到
CREATE_COMPLETE
状态的时间长度,单位为分钟。默认值为无超时。当 CloudFormation 检测到嵌套堆栈已达到CREATE_COMPLETE
状态时,它会在父堆栈中将该嵌套堆栈资源标记为CREATE_COMPLETE
,然后继续创建父堆栈。如果在嵌套堆栈达到CREATE_COMPLETE
之前超时结束,则 CloudFormation 将嵌套堆栈标记为已失败,并回滚嵌套堆栈和父堆栈。不支持更新。
必需:否
类型:整数
最低:
1
Update requires: No interruption
返回值
Ref
在将此资源的逻辑 ID 传递给内部 Ref
函数时,Ref
返回 堆栈 ID。例如:
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.
示例
指定堆栈参数
示例模板 EC2ChooseAMI.template 包含以下参数部分:
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"
嵌套堆栈
您可以使用以下模板来嵌入使用 EC2ChooseAMI.template 的堆栈 (myStackWithParams),并使用 AWS::CloudFormation::Stack 资源中的 Parameters 属性来指定 InstanceType 和 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"
另请参阅
-
有关示例模板代码段,请参阅 CloudFormation 模板代码段中的“嵌套堆栈”。
-
如果您的嵌套堆栈处于正在操作状态,请参阅 AWS CloudFormation 故障排查中的“纠正错误”。