CloudFormation - Intrinsic Functions

  1. Ref function helps to return the value of the parameter or resource [physical id]
  2. Fn::GetAtt function returns the value of an attribute for the specified resource
  3. Fn::FindInMap returns the value corresponding to specified keys.
  4. Fn::ImportValue allows you to import values from other templates that export values.
  5. Fn::Join allows you to join a set of values to a single value.
  6. Fn::Split allow you to split a string into a list of string values.
  7. Fn::Sub substitutes variables in an input string with values that you specify
  8. 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:

2022-06-12 18_20_19-54.66.203.169 (ec2-user).png

Output of StackRegion:

2022-06-12 14_35_07-54.66.203.169 (ec2-user).png