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
JSON
{ "Ref" : "logicalName" }
YAML
Syntax for the full function name:
Ref:logicalName
Syntax for the short form:
!ReflogicalName
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.
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 Type | Reference Value | Example Return Value |
|---|---|---|
| Alexa::ASK::Skill | Alexa skill ID | amzn1.ask.skill.a3103cee-c48c-40a0-a2c9-251141888863 |
| AWS::AmazonMQ::Broker | Amazon MQ broker ID | b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9 |
| AWS::AmazonMQ::Configuration | Amazon MQ configuration ID | c-1234a5b6-78cd-901e-2fgh-3i45j6k178l9 |
| AWS::AmazonMQ::ConfigurationAssociation | Amazon MQ configurationassociation ID | c-1234a5b6-78cd-901e-2fgh-3i45j6k178l9 |
|
API Gateway account resource ID |
|
|
|
API key |
|
|
|
Authorizer resource ID |
|
|
|
Client certificate name |
|
|
|
Deployment resource ID |
|
|
|
Domain name |
|
|
|
Method resource ID |
|
|
|
Model name |
|
|
|
API Gateway resource ID |
|
|
|
Rest API resource ID |
|
|
|
Stage name |
|
|
| AWS::ApplicationAutoScaling::ScalableTarget |
Scalable Target ID |
|
| AWS::ApplicationAutoScaling::ScalingPolicy |
Application Auto Scaling policy Amazon Resource Name (ARN) |
arn:aws:autoscaling:us-east-1:123456789012:scalingPolicy:12ab3c4d-56789-0ef1-2345-6ghi7jk8lm90:resource/ecs/service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH:policyName/MyStepPolicy |
|
Named query name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Scaling policy Amazon Resource Name (ARN) |
|
|
|
Name |
|
|
| AWS::Batch::ComputeEnvironment |
AWS Batch Compute Environment Amazon Resource Name (ARN) |
|
| AWS::Batch::JobDefinition |
AWS Batch Job Definition Amazon Resource Name (ARN) |
|
| AWS::Batch::JobQueue |
AWS Batch Job Queue Amazon Resource Name (ARN) |
|
| AWS::CertificateManager::Certificate |
Certificate Amazon Resource Name (ARN) |
|
|
Development environment ID |
|
|
|
Stack ID |
|
|
|
Name |
|
|
|
Wait Condition Signal URL |
|
|
|
Distribution ID |
|
|
|
Trail name |
|
|
|
Name |
|
|
|
Project name |
|
|
|
Repository ID |
|
|
| AWS::CodeDeploy::Application |
Application name |
|
| AWS::CodeDeploy::DeploymentConfig |
Deployment configuration name |
|
| AWS::CodeDeploy::DeploymentGroup |
Deployment group name |
|
| AWS::CodePipeline::CustomActionType |
Custom action name |
|
| AWS::CodePipeline::Pipeline |
Pipeline name |
|
| AWS::CodePipeline::Webhook |
Webhook name |
|
| AWS::Config::ConfigRule |
Configuration rule name |
|
| AWS::Config::ConfigurationRecorder |
Configuration recorder name |
|
| AWS::Config::DeliveryChannel |
Delivery channel name |
|
| AWS::DataPipeline::Pipeline |
Pipeline ID |
|
|
|
|
|
| AWS::DirectoryService::MicrosoftAD |
Microsoft directory ID |
|
| AWS::DirectoryService::SimpleAD |
Directory ID |
|
| AWS::DLM::LifecyclePolicy | Policy ID |
|
| AWS::DynamoDB::Table |
Table Name |
|
|
Fleet ID |
|
|
|
Elastic IP Address |
|
|
|
Name |
|
|
|
Flow log ID |
|
|
|
Host ID |
|
|
|
Instance ID |
|
|
|
NAT gateway ID |
|
|
|
Network interface permission ID |
|
|
|
Placement group name |
|
|
|
Route table ID |
rtb-12a34567 |
|
|
Name or security group ID (for VPC security groups that are not in a default VPC) |
|
|
|
Name |
|
|
|
Name |
|
|
|
Subnet ID |
|
|
|
Volume ID |
|
|
|
Name |
|
|
|
VPC ID |
|
|
| AWS::EC2::VPCPeeringConnection |
VPC peering connection ID |
|
|
Endpoint ID |
|
|
|
Repository name |
|
|
|
Name |
|
|
|
Service ARN |
|
|
|
Task definition ARN |
|
|
|
File system ID |
|
|
|
Mount target ID |
|
|
|
Name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Listener's Amazon Resource Name (ARN) |
|
|
|
Listener rule's Amazon Resource Name (ARN) |
|
|
|
Application load balancer's Amazon Resource Name (ARN) |
|
|
|
Target group's Amazon Resource Name (ARN) |
|
|
|
Domain name |
|
|
|
Cluster ID |
|
|
|
Instance group ID |
|
|
|
Name |
|
|
|
Step ID |
|
|
|
Name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Event bus policy ID |
|
|
|
Event rule ID |
|
|
|
Alias ID |
|
|
|
Build ID |
|
|
|
Fleet ID |
|
|
|
Name |
|
|
|
|
|
|
|
Name |
|
|
|
|
|
|
|
Name |
|
|
|
|
|
|
|
Name |
|
|
|
Detector ID |
|
|
|
IPSet ID |
|
|
|
Master ID |
|
|
|
Member ID |
|
|
|
ThreatIntel Set ID |
|
|
|
AccessKeyId |
|
|
|
Group name |
|
|
|
Policy ARN |
|
|
|
Name |
|
|
|
User name |
|
|
| AWS::IoT::Certificate | Certificate ID | a1234567b89c012d3e4fg567hij8k9l01mno1p23q45678901rs234567890t1u2 |
| AWS::IoT::Policy | Policy name | MyPolicyName |
| AWS::IoT::Thing | Thing name | MyStack-MyThing-AB1CDEFGHIJK |
| AWS::IoT::TopicRule | Topic rule name | MyStackMyTopicRule12ABC3D456EFG |
| AWS::IoT1Click::Placement | The placement name (associated with a project). | region3 |
| AWS::IoT1Click::Project | The project ARN. | arn:aws:iot1click:us-west-2:0123456789012:projects/seattle-region |
| AWS::IoT1Click::Device | The device ARN. | arn:aws:iot1click:us-west-2:123456789012:devices/G030PX0312744DWM |
|
Name |
|
|
|
Consumer ARN |
|
|
|
Delivery stream name |
|
|
|
Alias name |
|
|
|
Key ID |
|
|
|
Amazon Resource Name of the AWS Lambda alias |
arn:aws:lambda:us-west-2:123456789012:function:helloworld:BETA |
|
|
Name |
|
|
|
Name |
|
|
|
Layer version ARN. |
|
|
|
Layer version ARN with statement ID. |
|
|
|
Amazon Resource Name of the AWS Lambda version |
arn:aws:lambda:us-west-2:123456789012:function:helloworld:1 |
|
|
Destination name |
|
|
|
Name |
|
|
|
Log stream name |
|
|
|
AWS OpsWorks Application ID |
|
|
|
AWS OpsWorks Instance ID |
|
|
|
AWS OpsWorks Layer ID |
|
|
|
AWS OpsWorks Stack ID |
|
|
|
IAM user Amazon Resource Name |
|
|
|
AWS OpsWorks Volume ID |
|
|
|
Cluster name |
|
|
|
Parameter group name |
|
|
|
Name |
|
|
|
Name |
|
|
|
DB subnet group name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Amazon Route 53 health check ID |
|
|
| Hosted zone ID |
|
|
| Endpoint ID |
|
|
| Rule ID |
|
|
|
Name |
|
|
| AWS::SecretsManager::Secret | Secret ARN | arn:aws:secretsmanager:us-east-2:123456789012:secret:MyPath/MySecretName-a1b2c3 |
|
Id |
|
|
|
Name |
|
|
|
Name |
|
|
|
Name |
|
|
|
Topic ARN |
|
|
|
Queue URL |
|
|
|
SSM document name |
|
|
|
Maintenance window ID |
|
|
|
Maintenance window target ID |
|
|
|
Maintenance window task ID |
|
|
|
Patch baseline ID |
The ID of the default patch baseline provided by AWS is an ARN—for
example
|
|
| AWS::StepFunctions::Activity | Amazon Resource Name (ARN) of the AWS Step Functions activity | arn:aws:states:us-east-1:111122223333:activity:myActivity |
| AWS::StepFunctions::StateMachine | ARN of the created Step Functions state machine | arn:aws:states:us-east-1:111122223333:stateMachine:MyStateMachine-ABCDEFGHIJ1K |
|
Byte match ID |
|
|
|
IP set ID |
|
|
|
Rule ID |
|
|
|
Size constraint set ID |
|
|
|
SQL match set ID |
|
|
|
Web ACL ID |
|
|
|
XSS match set ID |
|
|
|
Byte match ID |
|
|
|
IP set ID |
|
|
|
Rule ID |
|
|
|
Size constraint set ID |
|
|
|
SQL match set ID |
|
|
|
Web ACL ID |
|
|
|
XSS match set ID |
|
|
|
Workspace ID |
|
|
|
AWS::AccountId |
|
|
|
AWS::NotificationARNs |
|
|
|
AWS::NoValue |
Does not return a value. |
|
|
AWS::Partition |
|
|
|
AWS::Region |
|
|
|
AWS::StackId |
|
|
|
AWS::StackName |
|
