I'm trying to figure out the differences between GetAtt
vs Ref
vs ${}
.
From what I understand you use GetAtt
to refer to objects within the same template only and Ref
can be used to refer to anything? Plus when would I use ${}
?
GetAtt is essentially the same as the 2nd function of Ref above, it also returns an attribute of the resource that you created within your resource, but while ref returns only a default attribute, GetAtt allows you to choose from different attributes to return.
For some resources, an identifier is returned that has another significant meaning in the context of the resource. An AWS::EC2::EIP resource, for instance, returns the IP address, and an AWS::EC2::Instance returns the instance ID. You can also use Ref to add values to Output messages.
YAML. Ref: logicalName. Ref function is used to enter the logical name of another resource. Ref function returns the value that is predefined for each resource. For example, your EC2 instance has a logical name of EC2.
Ref can be used for two things:
GetAtt is essentially the same as the 2nd function of Ref above, it also returns an attribute of the resource that you created within your resource, but while ref returns only a default attribute, GetAtt allows you to choose from different attributes to return.
Example, GetAtt for an EC2 instance gives you the option to return the AvailabilityZone, PrivateDnsName, PublicDNSName, etc of an instance - whereas Ref will only return the InstanceID. The different attributes you can return are different per resource type. You can also look at the bottom of each cloudformation resources page in the AWS docs to see what attributes you can all return (See Return Values section: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html)
${} is another way to reference parameters passed in through the parameters section of the template.
All of this is in the AWS documentation though.
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