Search code examples
amazon-web-servicesaws-cloudformationcloud-init

Reference "Self" in aws cloudformation template?


I've got an EC2 resource defined in Cloudformation like so:

Resources:
  FooInstance:
    Type: 'AWS::EC2::Instance'
    Properties:
      blah: blah
      blah: blah
      UserData:
        Fn::Base64: !Sub |
            #!/bin/bash
            /opt/aws/bin/cfn-init --stack ${AWS::StackId} --resource FooInstance --region ${AWS::Region}

Is there a special variable/replacement string to reference "self" in that UserData cfn-init block instead of explicitly declaring FooInstance? It would help make definitions much more copypastable for my team.

Thanks!


Solution

  • Unfortunately, no. This would be a very nice add-on for both UserData and AWS::CloudFormation::Init parts, but AWS still doesn't support it.