230k views
4 votes
In CloudFormation, What is the function that returns the value of an attribute from a resource in the template?

1) Fn::GetAtt
2) Fn::Ref
3) Fn::ImportValue
4) Fn::Sub

1 Answer

3 votes

Final answer:

The function in CloudFormation that returns the value of an attribute from a resource is Fn::GetAtt. It requires the logical name of the resource and the attribute to return its value. Fn::Ref, Fn::ImportValue, and Fn::Sub have different use cases in CloudFormation templates.

Step-by-step explanation:

The function in CloudFormation that returns the value of an attribute from a resource in the template is Fn::GetAtt. This intrinsic function is used to retrieve the value of an attribute from a resource in your stack. You need to provide the logical name of the resource and the desired attribute, and the Fn::GetAtt function returns its value. For example, to get the DNS name of an EC2 instance, you would specify Fn::GetAtt with the resource's logical name and the attribute 'PublicDnsName'.

Here's how you would generally use it in a CloudFormation template:

{
"Fn::GetAtt": ["LogicalNameOfResource", "AttributeName"]
}

Other functions mentioned such as Fn::Ref, Fn::ImportValue, and Fn::Sub serve different purposes. Fn::Ref is used to return the value of a specified parameter or resource, Fn::ImportValue returns the value of an output exported by another stack, and Fn::Sub substitutes variables in an input string.

User Sandra Rossi
by
7.2k points