Course contentsShow
← Cloud and Infrastructure
Lesson 864 of 2,98916. AWS CloudFormationFree lesson

Fn::GetAtt for Resource Attributes

Retrieve attributes from resources like ARNs, IPs, or DNS names using GetAtt function.

Fn::GetAtt for Resource Attributes

What you'll learn: How to retrieve dynamic attributes like ARNs, IP addresses, and DNS names from CloudFormation resources after they're created.

The Core Concept

While Ref returns the primary identifier of a resource, Fn::GetAtt (short for "Get Attribute") lets you access any other attribute that AWS exposes about that resource. Think of it this way: Ref is like asking "What's your ID number?" while Fn::GetAtt is like asking "What's your email address, phone number, or home address?" — it retrieves the extra details.

Many AWS resources generate information only after creation — like an EC2 instance's public IP address or an S3 bucket's domain name. You can't know these values when writing your template, but CloudFormation captures them during stack creation. Fn::GetAtt gives you access to this runtime information.

Syntax

!GetAtt LogicalResourceName.AttributeName

Or in JSON:

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

Practical Example

Resources:
  MyBucket:
    Type: AWS::S3::Bucket

Outputs:
  BucketArn:
    Value: !GetAtt MyBucket.Arn
  BucketDomainName:
    Value: !GetAtt MyBucket.DomainName

Here, MyBucket.Arn retrieves the bucket's full Amazon Resource Name, while MyBucket.DomainName gets its DNS endpoint — neither of which you could hardcode beforehand.

What Attributes Are Available?

Each resource type exposes different attributes. Check the CloudFormation documentation for your specific resource type to see the complete list. Common examples include ARNs, DNS names, IP addresses, and IDs of related resources.

Key Takeaway: Fn::GetAtt retrieves runtime attributes from resources that aren't available until after AWS creates them, giving you access to essential information like ARNs, DNS names, and IP addresses for use elsewhere in your template or outputs.