Skip to main content
Welcome to the lesson on accessing mapped values in an AWS CloudFormation template. This page explains how to use the Fn::FindInMap intrinsic function (YAML short form: !FindInMap) to look up static values from the template’s Mappings section. Use this when you want region-, environment-, or configuration-specific values centralized and referenced cleanly across resources.
A blue-green gradient presentation slide with the centered title "Accessing Mapped Values." There is a small "© Copyright KodeKloud" notice in the lower-left corner.
How Fn::FindInMap works
  • Fn::FindInMap performs a static lookup at stack creation or update.
  • It requires three arguments: the mapping name, the top-level key (row), and the second-level key (column/label).
  • The function returns the mapped value found at that intersection.
Syntax (short and long forms)
# Short form (YAML)
!FindInMap [MappingName, TopLevelKey, SecondLevelKey]

# Long form (YAML explicit)
Fn::FindInMap:
  - MappingName
  - TopLevelKey
  - SecondLevelKey
Example: define a mapping and use FindInMap to pick an AMI based on region
AWSTemplateFormatVersion: '2010-09-09'
Description: Example of using Fn::FindInMap

Mappings:
  RegionMap:
    us-east-1:
      AMI: ami-0abcdef1234567890
      HVM: hvm
    us-west-2:
      AMI: ami-0fedcba9876543210
      HVM: hvm2

Resources:
  MyInstance:
    Type: AWS::EC2::Instance
    Properties:
      # Use the current region (pseudo parameter) to look up the AMI
      ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", AMI]
      InstanceType: t2.micro
Arguments summary
Argument positionDescriptionExample
1 (MappingName)The name of the mapping under the template’s Mappings sectionRegionMap
2 (TopLevelKey)The top-level key (row) to select within the mapping. Can be a literal or an intrinsic (e.g., !Ref)!Ref “AWS::Region” or “us-east-1”
3 (SecondLevelKey)The second-level key (column/label) identifying the specific value in the selected rowAMI
Tips and common patterns
  • Use !Ref “AWS::Region” (or other intrinsics) as the TopLevelKey to select region-specific entries.
  • Keys and values are literal strings and case-sensitive—ensure the mapping keys match exactly.
  • You can nest other intrinsic functions inside the arguments (for example, !Ref, !FindInMap cannot call other mappings but can be used alongside other intrinsics in the same template).
  • Fn::FindInMap fails the stack operation if the specified mapping, or keys, do not exist—validate your mappings and test with different regions.
Mappings must be declared under the template’s Mappings section. Fn::FindInMap performs a static lookup at stack create/update — mapping values are part of the template and not dynamically generated outside intrinsic functions.
Warning: common pitfalls
If a mapping name or key is missing or misspelled, CloudFormation will fail the stack operation. Remember that mapping keys are case-sensitive and must match exactly.
Quick reference (one-line)
!FindInMap [MappingName, TopLevelKey, SecondLevelKey]
Links and references

Watch Video