Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 662
Eric Avatar asked Oct 16 '18 19:10

Eric


People also ask

What is ref in CloudFormation template?

The intrinsic function Ref returns the value of the specified parameter or resource. When you specify a parameter's logical name, it returns the value of the parameter. When you specify a resource's logical name, it returns a value that you can typically use to refer to that resource, such as a physical ID.

How do you reference existing resources in CloudFormation?

To import existing resources into a CloudFormation stack, you need to provide: A template that describes the entire stack, including both the resources to import and (for existing stacks) the resources that are already part of the stack. Each resource to import must have a DeletionPolicy attribute in the template.

What is FN :: GetAtt in CloudFormation?

The Fn::GetAtt intrinsic function returns the value of an attribute from a resource in the template. For more information about GetAtt return values for a particular resource, refer to the documentation for that resource in the Resource and property reference.

How can I reference a resource in another stack from an AWS CloudFormation template?

Note: To reference a resource in another AWS CloudFormation stack, you must create cross-stack references. To create a cross-stack reference, use the export field to flag the value of a resource output for export.


1 Answers

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.

like image 68
tyron Avatar answered Oct 23 '22 04:10

tyron