Intrinsic functions in CloudFormation
25 February, 2023
4
4
1
Contributors
CloudFormation is a very popular and widely used service of AWS. it is an infrastructure as a code service. we declare all the resources in the cloud formation template in the form of JSON or YAML format.
Intrinsic functions in CloudFormation are built-in functions that help us assign values to attributes at runtime. Here we will discuss a few intrinsic functions.
Ref
The Ref function returns the value of attributes or resources.
Example
MyEIP:
Type: "AWS::EC2::EIP"
Properties:
InstanceId: !Ref MyEC2Instance
Fn::GetAtt
The Fn::GetAtt function returns an attribute's value from a resource in the template.
Syntax
Fn::GetAtt: [ logicalNameOfResource, attributeName ]
#Example
!GetAtt myELB.DNSName
Fn::FindInMap
We use Fn::FindInMap to return a named value from a specific key.
Syntax
Fn::FindInMap: [ MapName, TopLevelKey, SecondLevelKey ]
#Syntax
for the short form
!FindInMap [ MapName, TopLevelKey, SecondLevelKey ]
Fn::ImportValue
We use Fn::ImportValue when we import the value of an output exported by another stack.
Syntax
Fn::ImportValue: sharedValueToImport
Alternatively, you can use the short form
!ImportValue sharedValueToImport