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

Declaration

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

"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::ApiGateway::Account

API Gateway account resource ID

mysta-accou-01234b567890example

AWS::ApiGateway::ApiKey

API key

AbCdEfG01234567890ExampleKey

AWS::ApiGateway::Authorizer

Authorizer resource ID

abcde1

AWS::ApiGateway::ClientCertificate

Client certificate name

abc123

AWS::ApiGateway::Deployment

Deployment resource ID

abc123

AWS::ApiGateway::Method

Method resource ID

mysta-metho-01234b567890example

AWS::ApiGateway::Model

Model name

myModel

AWS::ApiGateway::Resource

API Gateway resource ID

abc123

AWS::ApiGateway::RestApi

Rest API resource ID

a1bcdef2gh

AWS::ApiGateway::Stage

Stage name

MyTestStage

AWS::ApiGateway::Account

ID

mysta-accou-01234b567890example

AWS::AutoScaling::AutoScalingGroup

Name

mystack-myasgroup-NT5EUXTNTXXD

AWS::AutoScaling::LaunchConfiguration

Name

mystack-mylaunchconfig-1DDYF1E3B3I

AWS::AutoScaling::LifecycleHook

Name

mylifecyclehookname

AWS::AutoScaling::ScalingPolicy

Scaling policy Amazon Resource Name (ARN)

arn:aws:autoscaling:us-east-1:123456789012:scalingPolicy:ab12c4d5-a1b2-a1b2-a1b2-ab12c4d56789:autoScalingGroupName/myStack-AutoScalingGroup-AB12C4D5E6:policyName/myStack-myScalingPolicy-AB12C4D5E6

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::CodeDeploy::Application

Application name

myapplication-a123d0d1

AWS::CodeDeploy::DeploymentConfig

Deployment configuration name

mydeploymentconfig-a123d0d1

AWS::CodeDeploy::DeploymentGroup

Deployment group name

mydeploymentgroup-a123d0d1

AWS::CodePipeline::CustomActionType

Custom action name

mysta-MyCus-A1BCDEFGHIJ2

AWS::CodePipeline::Pipeline

Pipeline name

mysta-MyPipeline-A1BCDEFGHIJ2

AWS::Config::ConfigRule

Configuration rule name

mystack-MyConfigRule-12ABCFPXHV4OV

AWS::Config::ConfigurationRecorder

Configuration recorder name

default

AWS::Config::DeliveryChannel

Delivery channel name

default

AWS::DataPipeline::Pipeline

Pipeline ID

df-sample322HVPGK130TOD

AWS::DirectoryService::MicrosoftAD

Microsoft directory ID

d-12345ab592

AWS::DirectoryService::SimpleAD

Directory ID

d-12345ab592

AWS::EC2::EIP

Elastic IP Address

192.0.2.0

AWS::EC2::EIPAssociation

Name

mystack-myeipa-1NU3IL8LJ313N

AWS::EC2::FlowLog

Flow log ID

fl-1a23b456

AWS::EC2::Host

Host ID

h-0ab123c45d67ef89

AWS::EC2::Instance

Instance ID

i-636be302

AWS::EC2::NatGateway

NAT gateway ID

nat-0a12bc456789de0fg

AWS::EC2::PlacementGroup

Placement group name

mystack-myplacementgroup-CU6107MRVLR7

AWS::EC2::RouteTable

Route table ID

rtb-12a34567

AWS::EC2::SecurityGroup

Name or security group ID (for VPC security groups that are not in a default VPC)

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::ECR::Repository

Repository name

test-repository

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::Elasticsearch::Domain

Domain name

mystack-elasticsea-abc1d2efg3h4

AWS::EMR::Cluster

Cluster ID

j-1ABCD123AB1A

AWS::EMR::InstanceGroupConfig

Instance group ID

ig-ABC12DEF3456

AWS::EMR::Step

Step ID

s-1A2BC3D4EFG56

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::Events::Rule

Event rule ID

mystack-ScheduledRule-ABCDEFGHIJK

AWS::GameLift::Alias

Alias ID

myalias-a01234b56-7890-1de2-f345-g67h8i901j2k

AWS::GameLift::Build

Build ID

mybuild-a01234b56-7890-1de2-f345-g67h8i901j2k

AWS::GameLift::Fleet

Fleet ID

myfleet-a01234b56-7890-1de2-f345-g67h8i901j2k

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::KinesisFirehose::DeliveryStream

Delivery stream name

mystack-deliverystream-1ABCD2EF3GHIJ

AWS::KMS::Key

Key ID

123ab456-a4c2-44cb-95fd-b781f32fbb37

AWS::Lambda::Alias

Amazon Resource Name of the AWS Lambda alias

arn:aws:lambda:us-west-2:123456789012:function:helloworld:BETA

AWS::Lambda::EventSourceMapping

Name

MyStack-lambdaeventsourcemapping-CU6107MRVLR7

AWS::Lambda::Function

Name

MyStack-AMILookUp-NT5EUXTNTXXD

AWS::Lambda::Version

Amazon Resource Name of the AWS Lambda version

arn:aws:lambda:us-west-2:123456789012:function:helloworld:1

AWS::Logs::Destination

Destination name

TestDestination

AWS::Logs::LogGroup

Name

mystack-myLogGroup-1341JS4M96031

AWS::Logs::LogStream

Log stream name

MyAppLogStream

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::RDS::DBCluster

Cluster name

test-rdscluster-pdedtss0mfqr

AWS::RDS::DBClusterParameterGroup

Parameter group name

test-dbparamgroup-4l8qqx46vjby

AWS::RDS::DBInstance

Name

mystack-mydb-ea5ugmfvuaxg

AWS::RDS::DBSecurityGroup

Name

mystack-mydbsecuritygroup-1k5u5dxjb0nxs

AWS::RDS::DBSubnetGroup

DB subnet group name

mystack-mydbsubnetgroup-1k5u5dxjb0nxs

AWS::RDS::OptionGroup

Name

mystack-myoptiongroup-1qmfawfea4vmz

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::Route53::HealthCheck

Amazon Route 53 health check ID

e0a123b4-4dba-4650-935e-example

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

AWS::SSM::Document

SSM document name

ssm-myinstanceconfig-ABCNPH3XCAO6

AWS::WAF::ByteMatchSet

Byte match ID

aabc123a-fb4f-4fc6-becb-2b00831cadcf

AWS::WAF::IPSet

IP set ID

aabc123a-fb4f-4fc6-becb-2b00831cadcf

AWS::WAF::Rule

Rule ID

aabc123a-fb4f-4fc6-becb-2b00831cadcf

AWS::WAF::SizeConstraintSet

Size constraint set ID

aabc123a-fb4f-4fc6-becb-2b00831cadcf

AWS::WAF::SqlInjectionMatchSet

SQL match set ID

aabc123a-fb4f-4fc6-becb-2b00831cadcf

AWS::WAF::WebACL

Web ACL ID

aabc123a-fb4f-4fc6-becb-2b00831cadcf

AWS::WAF::XssMatchSet

XSS match set ID

aabc123a-fb4f-4fc6-becb-2b00831cadcf

AWS::WorkSpaces::Workspace

Workspace ID

ws-cdd1gggh7

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