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!
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With