AWS CloudFormation
User Guide (API Version 2010-05-15)

Ref

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.

When you are declaring a resource in a template and you need to specify another template resource by name, you can use the Ref to refer to that other resource. In general, Ref returns the name of the resource. For example, a reference to an AWS::AutoScaling::AutoScalingGroup returns the name of that Auto Scaling group resource.

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.

At the bottom of this topic, there is a table that lists the values returned for many common resource types. More information about Ref return values for a particular resource or property can be found in the documentation for that resource or property.

Tip

You can also use Ref to add values to Output messages.

For more information about Ref return values for a particular resource or property, refer to the documentation for that resource or property in the Resource and Property Reference.

Declaration

JSON

{ "Ref" : "logicalName" }

YAML

Syntax for the full function name:

Ref: logicalName

Syntax for the short form:

!Ref logicalName

Parameters

logicalName

The logical name of the resource or parameter you want to dereference.

Return Value

The physical ID of the resource or the value of the parameter.

Example

The following resource declaration for an Elastic IP address needs the instance ID of an EC2 instance and uses the Ref function to specify the instance ID of the MyEC2Instance resource:

JSON

"MyEIP" : { "Type" : "AWS::EC2::EIP", "Properties" : { "InstanceId" : { "Ref" : "MyEC2Instance" } } }

YAML

MyEIP: Type: "AWS::EC2::EIP" Properties: InstanceId: !Ref MyEC2Instance

Supported Functions

You cannot use any functions in the Ref function. You must specify a string that is a resource logical ID.