CloudFormation - Intrinsic Functions
- Ref function helps to return the value of the parameter or resource [physical id]
- Fn::GetAtt function returns the value of an attribute for the specified resource
- Fn::FindInMap returns the value corresponding to specified keys.
- Fn::ImportValue allows you to import values from other templates that export values.
- Fn::Join allows you to join a set of values to a single value.
- Fn::Split allow you to split a string into a list of string values.
- Fn::Sub substitutes variables in an input string with values that you specify
- Fn::Select returns a single object from a list of objects by index.
AWSTemplateFormatVersion: 2010-09-09
Description: Functions Demo - CF
Resources:
myEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: "ami-0c6120f461d6b39e9"
InstanceType: "t2.micro"
SecurityGroupIds:
- "sshSG"
Tags:
- Key: "Name"
Value: !Ref AWS::StackName
Outputs:
InstanceIP:
Description: Public IP of Instance
Value: !GetAtt myEC2Instance.PublicIp
StackDetails:
Description: Stack Details
Value: !Join
- ''
- - !Ref AWS::StackName
- "__"
- !Ref AWS::StackId
StackRegion:
Description: Stack Region
Value: !Select [ 3, !Split [ ":", !Ref AWS::StackId]]
Output of StackDetails:
Output of StackRegion: