如何获取资源逻辑ID cloudformation模板?

How to get resource logical id cloudformation template?

是否有可能像我们对 "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" ]} }
                ]
            }
        }
    }

我只想在键、值标记行中获取资源名称(例如实例 1 或实例 2)。

无法在自定义标签中检索逻辑名称本身,但 CloudFormation 会自动为每个实例添加 aws:cloudformation:logical-id 标签。

In addition to any tags you define, AWS CloudFormation automatically creates the following stack-level tags with the prefix aws::

  • aws:cloudformation:logical-id
  • aws:cloudformation:stack-id
  • aws:cloudformation:stack-name

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html