Menu
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.

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.

Declaration

"Ref" : "logicalName"

Parameters

logicalName

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

Return Value

The value of the MyInputParameter 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:


"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.

Resource Return Examples

This section lists sample values returned by Ref for particular AWS CloudFormation resources. For more information about Ref return values for a particular resource or property, refer to the documentation for that resource or property.

Resource TypeReference ValueExample Return Value

AWS::AutoScaling::AutoScalingGroup

Name

mystack-myasgroup-NT5EUXTNTXXD

AWS::AutoScaling::LaunchConfiguration

Name

mystack-mylaunchconfig-1DDYF1E3B3I

AWS::AutoScaling::LifecycleHook

Name

mylifecyclehookname

AWS::AutoScaling::ScalingPolicy

Name

mystack-myaspolicy-1DDYF1E3B3I

AWS::AutoScaling::ScheduledAction

Name

mystack-myscheduledaction-NT5EUXTNTXXD

AWS::CloudFormation::Stack

Stack ID

arn:aws:cloudformation:us-east-1:803981987763:stack/mystack-mynestedstack-sggfrhxhum7w/f449b250-b969-11e0-a185-5081d0136786

AWS::CloudFormation::WaitCondition

Name

arn:aws:cloudformation:us-east-1:803981987763:stack/mystack/c325e210-bdf2-11e0-9638-50690880c386/mywaithandle

AWS::CloudFormation::WaitConditionHandle

Wait Condition Signal URL

https://cloudformation-waitcondition-us-east-1.s3.amazonaws.com/arn%3Aaws%3Acloudformation%3Aus-east-1%3A803981987763%3Astack%2Fwaittest%2F054a33d0-bdee-11e0-8816-5081c490a786%2FmyWaitHandle?Expires=1312475488&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Signature=tUsrW3WvWVT46K69zMmgbEkwVGo%3D

AWS::CloudFront::Distribution

Distribution ID

E27LVI50CSW06W

AWS::CloudTrail::Trail

Trail name

awscloudtrail-example

AWS::CloudWatch::Alarm

Name

mystack-myalarm-3AOHFRGOXR5T

AWS::DataPipeline::Pipeline

Pipeline ID

df-sample322HVPGK130TOD

AWS::EC2::EIP

Elastic IP Address

192.0.2.0

AWS::EC2::EIPAssociation

Name

mystack-myeipa-1NU3IL8LJ313N

AWS::EC2::Instance

Instance ID

i-636be302

AWS::EC2::SecurityGroup

Name or security group ID (for VPC security groups)

mystack-mysecuritygroup-QQB406M8FISX or sg-94b3a1f6

AWS::EC2::SecurityGroupIngress

Name

mysecuritygroupingress

AWS::EC2::Subnet

Subnet ID

subnet-e19f0178

AWS::EC2::Volume

Volume ID

vol-3cdd3f56

AWS::EC2::VolumeAttachment

Name

mystack-myvola-ERXHJITXMRLT

AWS::EC2::VPC

VPC ID

vpc-18ac277d

AWS::EC2::VPCPeeringConnection

VPC peering connection ID

pcx-75de3e1d

AWS::EC2::VPCEndpoint

Enpoint ID

vpce-a123d0d1

AWS::ECS::Cluster

Name

MyStack-MyECSCluster-NT5EUXTNTXXD

AWS::ECS::Service

Service ARN

arn:aws:ecs:us-west-2:123456789012:service/sample-webapp

AWS::ECS::TaskDefinition

Task ARN

arn:aws:ecs:us-west-2:123456789012:task/1abf0f6d-a411-4033-b8eb-a4eed3ad252a

AWS::EFS::FileSystem

File system ID

fs-47a2c22e

AWS::EFS::MountTarget

Mount target ID

fsmt-55a4413c

AWS::ElastiCache::ReplicationGroup

Name

abc12xmy3d1w3hv6

AWS::ElastiCache::SubnetGroup

Name

myCachesubnetgroup

AWS::ElasticBeanstalk::Application

Name

mystack-myapplication-FM6BIXY7U8PK

AWS::ElasticBeanstalk::ApplicationVersion

Name

mystack-myapplicationversion-iy8ptveuxjly

AWS::ElasticBeanstalk::ConfigurationTemplate

Name

mystack-myconfigurationtemplate-108RPH64J195

AWS::ElasticBeanstalk::Environment

Name

mystack-myenv-LKGNQSFHO1DB

AWS::ElasticLoadBalancing::LoadBalancer

Name

mystack-myelb-1WQN7BJGDB5YQ

AWS::IAM::AccessKey

AccessKeyId

AKIAIOSFODNN7EXAMPLE

AWS::IAM::Group

Group name

mystack-mygroup-1DZETITOWEKVO

AWS::IAM::ManagedPolicy

Policy ARN

arn:aws:iam::123456789012:policy/teststack-CreateTestDBPolicy-16M23YE3CS700

AWS::IAM::User

User name

mystack-myuser-1CCXAFG2H2U4D

AWS::Kinesis::Stream

Name

mystack-mystream-1NAOH4L1RIQ7I

AWS::Lambda::Function

Name

MyStack-AMILookUp-NT5EUXTNTXXD

AWS::Logs::LogGroup

Name

mystack-myLogGroup-1341JS4M96031

AWS::OpsWorks::App

AWS OpsWorks Application ID

4fee5b96-0d10-4af1-bcc5-25f92e3c6acf

AWS::OpsWorks::Instance

AWS OpsWorks Instance ID

aa2e9ae2-2b4b-491c-aeb6-8bf3ce9400fe

AWS::OpsWorks::Layer

AWS OpsWorks Layer ID

730b238b-f7c4-461d-b7c0-3feb7ef1152a

AWS::OpsWorks::Stack

AWS OpsWorks Stack ID

5c9f04e8-370e-4bd3-ae09-a4bbcc2998bb

AWS::Redshift::Cluster

Name

mystack-myredshiftcluster-ranmiv3f0mad

AWS::Redshift::ClusterParameterGroup

Name

mysta-mypar-1AJYM1FL3WQBW

AWS::Redshift::ClusterSecurityGroup

Name

mystack-myredshiftclustersecuritygroup-bjy2afmhy3ee

AWS::Redshift::ClusterSubnetGroup

Name

mystack-myredshiftclustersubnetgroup-aq6rsdq8rp71

AWS::RDS::DBInstance

Name

mystack-mydb-ea5ugmfvuaxg

AWS::RDS::DBSecurityGroup

Name

mystack-mydbsecuritygroup-1k5u5dxjb0nxs

AWS::RDS::DBSecurityGroup

Name

mystack-mydbsecuritygroup-1k5u5dxjb0nxs

AWS::RDS::OptionGroup

Name

mystack-myoptiongroup-1qmfawfea4vmz

AWS::Route53::HostedZone

Hosted zone ID

Z23ABC4XYZL05B

AWS::S3::Bucket

Name

mystack-mys3bucket-1hbsmonr9mytq

AWS::SDB::Domain

Name

mystack-mysdbdomain-IVNAOZTDFVXL

AWS::SNS::Topic

Topic ARN

arn:aws:sns:us-east-1:123456789012:mystack-mytopic-NZJ5JSMVGFIE

AWS::SQS::Queue

Queue URL

https://sqs.us-east-1.amazonaws.com/803981987763/aa4-MyQueue-Z5NOSZO2PZE9

Pseudo Parameter

AWS::AccountId

123456789012

Pseudo Parameter

AWS::NotificationARNs

[arn:aws:sns:us-east-1:123456789012:MyTopic]

Pseudo Parameter

AWS::NoValue

Does not return a value.

Pseudo Parameter

AWS::Region

us-east-1

Pseudo Parameter

AWS::StackId

arn:aws:cloudformation:us-east-1:123456789012:stack/MyStack/1c2fa620-982a-11e3-aff7-50e2416294e0

Pseudo Parameter

AWS::StackName

MyStack