Last updated
Was this helpful?
Last updated
Was this helpful?
The !GetAtt
(Get Attribute) is a CloudFormation intrinsic function that helps you get the value of an attribute from a resource that has been created in your CloudFormation template.
In the example I showed earlier, !GetAtt NotificationFunction.Arn
is getting the ARN (Amazon Resource Name) of a Lambda function named "NotificationFunction".
Here are some common uses of !GetAtt:
The syntax is:
Where:
ResourceLogicalName: The logical name you gave to the resource in your template
AttributeName: The specific attribute you want to reference
This is particularly useful because:
You don't need to hardcode values
It ensures resources are properly linked together
CloudFormation will automatically resolve the actual value during deployment
It helps maintain dependencies between resources
For example, if you're creating a Lambda function and need to reference it in an EventBridge rule, you would:
The !Ref
(Reference) is another CloudFormation intrinsic function that allows you to refer to resources or parameters in your template. It's simpler than !GetAtt
because it typically returns a default value for the resource.
For different resource types, !Ref
returns different values:
For SNS Topics -> Returns the Topic ARN
For S3 Buckets -> Returns the Bucket name
For Parameters -> Returns the parameter value
For EC2 Instances -> Returns the instance ID
Here are some common examples:
In our previous EventBridge example:
The key differences between !Ref
and !GetAtt
:
!Ref
gets a default value:
!GetAtt
gets a specific attribute: