Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get resource logical id cloudformation template?

Is it possible to get a resource's logical ID inside itself like we do with "Ref" : "logicalName". I just want to get the resource logical id (here Instance1) in its own properties section dynamically. Till now i have to hard code resource name.

{
  "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" ]} }
                ]
            }
        }
    }

I just want to get resource name (eg Instance1 or instance 2) in key, value tag lines.

like image 924
Hardeep Singh Avatar asked Sep 13 '25 15:09

Hardeep Singh


1 Answers

It is not possible to retrieve the logical name itself within a custom tag, but CloudFormation does automatically tag every Instance with an aws:cloudformation:logical-id tag.

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

like image 106
Jason Avatar answered Sep 16 '25 07:09

Jason