是否可以像使用"Ref" : "logicalName"
一样获取资源的逻辑ID。我只想动态地在其自己的属性部分中获取资源逻辑id(此处为Instance1)。直到现在我必须硬编码资源名称。
{
"AWSTemplateFormatVersion": "2010-09-09",
"Mappings": {
"Para" : {
"Layer" : { "Instance1" : "Testing", "Instance2" : "Staging", "Instance3" : "Production" }
}
},
"Resources": {
"Instance1": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-5fb8c835",
"Tags": [
{ "Key": "Name", "Value": { "Fn::FindInMap" : [ "Para", "Name", "Instance1" ]} }
]
}
},
"Instance2": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-5fb8c835",
"Tags": [
{ "Key": "Name", "Value": { "Fn::FindInMap" : [ "Para", "Name", "Instance2" ]} }
]
}
}
}
我只想在键,值标记行中获取资源名称(例如Instance1或实例2)。
答案 0 :(得分:3)
无法在自定义标记中检索逻辑名称本身,但CloudFormation会自动使用aws:cloudformation:logical-id
标记标记每个实例。
除了您定义的任何标签,AWS CloudFormation也会自动生成 使用前缀aws ::
创建以下堆栈级标记
- AWS:cloudformation:逻辑-ID
- AWS:cloudformation:堆栈ID
- AWS:cloudformation:堆栈名称
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html