- Robert Boscacci/
- Projects/
- Certification: AWS DevOps Pro/
- 2: Configuration Mgmt / Infrastructure as Code/
- 2: CloudFormation/
- 1: CloudFormation Intrinsic Functions/
1: CloudFormation Intrinsic Functions
·1 min
Table of Contents
Ref
- Returns the value of the specified parameter or resource
- Json:
{ "Ref" : "logicalName" }
- Yaml:
!Ref logicalName
Fn:FindInMap
- It’s a hashmap lookup.
- Find e.g. AMI for a type of instance in a certain region
What are CF intrinsic functions?
- Built-in funcs to dynamically assign values to properties at runtime
- E.g. retrieve public IP of ec2 instance in the stack at runtime
Fn::GetAtt
- Returns value of an attribute from a resource
- JSON:
Fn::GetAtt: [logicalNameOfResource, attributeName]
Fn::ImportValue
- Returns value of an output exported by another stack
- (Cross-stack reference)
- Values are spit out from “output” section of another stack
- JSON:
"Fn::ImportValue" : {"Fn::Sub" : ${NetworkStackNameParameter}-SecurityGroupID"}
Fn::Sub
- String substitution builder
- JSON:
{"Fn::Sub": ["www.${Domain}", {"Domain": {"Ref": "RootDomainName"}}]}
Fn::Join
- Concatenate strings
- Yaml:
!Join [ "/", ["s3://mybucket", !Ref myfolder, "myfile.txt" ] ]
- Result:
"s3://mybucket/myFolderValue/myfile.txt"
Condition Funcs
- Boolean operators: And, or, if, not, equals
- If prod: Beefy server, if dev: scrappy box
- Create or not create resources based on conditions