💾 Archived View for cfdocs.wetterberg.nu › intrinsic-function-reference-ref.gemini captured on 2024-03-21 at 15:25:30. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-03)

-=-=-=-=-=-=-

Ref

Search

The intrinsic function `Ref` returns the value of the specified *parameter* or *resource*.

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.

AWS::AutoScaling::AutoScalingGroup

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.

AWS::EC2::EIP

AWS::EC2::Instance

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.

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.