> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Accessing Mapped Values

> Explains how to use the FindInMap intrinsic function in AWS CloudFormation to perform static lookups from the Mappings section for region and configuration specific values

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.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/7Vg7D5Qe0ykvRK48/images/AWS-CloudFormation/Mappings/Accessing-Mapped-Values/accessing-mapped-values-slide.jpg?fit=max&auto=format&n=7Vg7D5Qe0ykvRK48&q=85&s=954119e2ac4a9d386dbcb926dca3c048" alt="A blue-green gradient presentation slide with the centered title &#x22;Accessing Mapped Values.&#x22; There is a small &#x22;© Copyright KodeKloud&#x22; notice in the lower-left corner." width="1920" height="1080" data-path="images/AWS-CloudFormation/Mappings/Accessing-Mapped-Values/accessing-mapped-values-slide.jpg" />
</Frame>

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)

```yaml theme={null}
# 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

```yaml theme={null}
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 position  | Description                                                                                         | Example                           |
| ------------------ | --------------------------------------------------------------------------------------------------- | --------------------------------- |
| 1 (MappingName)    | The name of the mapping under the template's Mappings section                                       | RegionMap                         |
| 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 row              | AMI                               |

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.

<Callout icon="lightbulb" color="#1CB2FE">
  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.
</Callout>

Warning: common pitfalls

<Callout icon="warning" color="#FF6B6B">
  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.
</Callout>

Quick reference (one-line)

```yaml theme={null}
!FindInMap [MappingName, TopLevelKey, SecondLevelKey]
```

Links and references

* [AWS CloudFormation Fn::FindInMap documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html)
* [CloudFormation Intrinsic Functions overview](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html)
* [AWS CloudFormation Mappings section](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/aws-cloud-formation/module/4e0caf18-41ee-4499-8c83-b0dc280c537a/lesson/745550ff-7de7-4a8f-a572-55f1707a43d7" />
</CardGroup>
