gpt4 book ai didi

json - 将堆栈标签传递到 Cloudformation 中的嵌套堆栈

转载 作者:行者123 更新时间:2023-12-04 22:06:14 24 4
gpt4 key购买 nike

我可以使用 AWS::CloudFormation::Stack 轻松地将参数传递到嵌套 Cloudformation 堆栈,包括引用值:

"MyNestedStack" : {
"Type" : "AWS::CloudFormation::Stack",
"Condition" : "MyCondition",
"Properties" : {
"TemplateURL" : {
"Fn::Join" : ["", ["https://mybucket.s3.amazonaws.com/", {
"Ref" : "S3BucketLocation"
}, "/MyNestedStack.template"]]
},
"Parameters": {
"MyVPC" : {
"Ref" : "VPC"
},
"MySubnet" : {
"Ref" : "ManagementSubnet"
},
"MySubnetAZ" : {
"Fn::GetAtt" : [ "ManagementSubnet", "AvailabilityZone" ]
}
"InstanceType" : "m3.large",
"KeyName" : "MyKey",
}
}
}

但是我找不到任何文档如何将应用于父堆栈的堆栈标签传递到子(嵌套)堆栈。

原始堆栈被调用:

#Create Stack
aws cloudformation create-stack --parameters ${parms} --tags Key='Environment Name',Value=${name} Key=Name,Value=${env} --stack-name ${env} --template-url ${url}

Environment nameName 标记应用于原始堆栈中的资源(例如实例),但不适用于嵌套堆栈中的资源或嵌套堆栈本身。

最佳答案

AWS 已实现将堆栈标签传播到子堆栈。我找不到反射(reflect)此更改的公告或文档,但它现在可以使用。

AWS CloudFormation Resource Tags Type页面状态:

All stack-level tags, including automatically created tags, are propagated to resources that AWS CloudFormation supports.

在下面的父/子堆栈模板示例中,父堆栈上的堆栈标签传播到父堆栈中的 EC2 实例、子堆栈、子堆栈中的 EC2 实例。

注意:EC2 标签仍然不会传播到从 block 储存设备映射创建的卷。

父堆栈示例

{
"AWSTemplateFormatVersion" : "2010-09-09",

"Description" : "Test Child Stack Tag Propagation (Parent Stack)",

"Parameters" : {
"KeyName": {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "AWS::EC2::KeyPair::KeyName"
},

"Subnet": {
"Type": "AWS::EC2::Subnet::Id"
},

"VPC": {
"Type": "AWS::EC2::VPC::Id"
},

"AMI": {
"Type": "AWS::EC2::Image::Id",
"Default": "ami-f2210191"
},

"ChildTemplateUrl": {
"Type" : "String"
}
},

"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"InstanceType" : "t2.nano",
"SecurityGroupIds" : [{"Ref" : "InstanceSecurityGroup"}],
"SubnetId" : { "Ref" : "Subnet" },
"KeyName" : { "Ref" : "KeyName" },
"ImageId" : {"Ref": "AMI"}
}
},

"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH access via port 22",
"VpcId" : { "Ref": "VPC"},
"SecurityGroupIngress" : [ {
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : "0.0.0.0/0"
} ]
}
},

"MyNestedStack" : {
"Type" : "AWS::CloudFormation::Stack",
"Properties" : {
"TemplateURL" : {"Ref": "ChildTemplateUrl"},
"Parameters": {
"Subnet" : {"Ref": "Subnet"},
"KeyName" : {"Ref": "KeyName"},
"AMI" : {"Ref": "AMI"},
"SecurityGroup": {"Ref" : "InstanceSecurityGroup"},
"VPC": {"Ref": "VPC"}
}
}
}
},

"Outputs" : {
"InstanceId" : {
"Description" : "InstanceId of the newly created EC2 instance",
"Value" : { "Ref" : "EC2Instance" }
},
"IP" : {
"Description" : "Private IP address of the newly created VPC EC2 instance",
"Value" : { "Fn::GetAtt" : [ "EC2Instance", "PrivateIp" ] }
}
}
}

子堆栈示例

{
"AWSTemplateFormatVersion" : "2010-09-09",

"Description" : "Test Child Stack Tag Propagation (Child Stack)",

"Parameters" : {
"KeyName": {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "AWS::EC2::KeyPair::KeyName"
},

"Subnet": {
"Type": "AWS::EC2::Subnet::Id"
},

"VPC": {
"Type": "AWS::EC2::VPC::Id"
},

"AMI": {
"Type": "AWS::EC2::Image::Id"
},

"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup::Id"
}
},

"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"InstanceType" : "t2.nano",
"SecurityGroupIds" : [{"Ref" : "SecurityGroup"}],
"SubnetId" : { "Ref" : "Subnet" },
"KeyName" : { "Ref" : "KeyName" },
"ImageId" : {"Ref": "AMI"}
}
}
},

"Outputs" : {
"InstanceId" : {
"Description" : "InstanceId of the newly created EC2 instance",
"Value" : { "Ref" : "EC2Instance" }
},
"IP" : {
"Description" : "Private IP address of the newly created VPC EC2 instance",
"Value" : { "Fn::GetAtt" : [ "EC2Instance", "PrivateIp" ] }
}
}
}

关于json - 将堆栈标签传递到 Cloudformation 中的嵌套堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27613867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com