Mappings are static. You cannot use intrinsic functions or parameter references inside the Mappings section; all mapping values must be literal constants.
Anatomy of a mapping
A CloudFormation mapping is a nested lookup table with three conceptual parts:- Mapping name — the top-level identifier (for example, DevMap).
- Top-level key — the first-level entries inside the mapping (for example, Arno or Alice).
- Second-level key — the nested label inside each top-level key (for example, Env).
- Value — the literal constant associated with the second-level key (for example, Development).
| Part | Example | Description |
|---|---|---|
| Mapping name | DevMap | Top-level label for the whole mapping |
| Top-level key | Arno, Alice | First-level lookup keys inside the mapping |
| Second-level key | Env | Nested lookup label used in FindInMap calls |
| Value | Development, Production | Literal constants returned by the lookup |
Using a mapping (FindInMap)
To read values from a mapping, use the intrinsic function FindInMap (short form: !FindInMap or long form: Fn::FindInMap). The lookup requires three arguments:- Mapping name
- Top-level key
- Second-level key
When to use mappings
Mappings are best for static, template-time lookups with predictable, constant values. Use them when you need to:| Use case | Why use a mapping |
|---|---|
| Region -> AMI ID | Different AMIs per region, fixed per template |
| Account -> settings | Account-specific values that don’t change at runtime |
| Environment labels | Map tenant or hostnames to environment names |
| Static configuration | Any constant lookup not depending on runtime logic |
Mappings are defined in the template and must contain literal values. Do not include intrinsic functions or parameter references inside the Mappings section — those values must be constants.
Best practices
- Keep mapping entries small and focused (e.g., separate mappings for AMIs and environment labels).
- Use clear, consistent top-level key names (for example, account IDs, tenant names, or region codes).
- Prefer parameters or pseudo-parameters as arguments to !FindInMap when the actual lookup key needs to vary at template runtime.
- Store large or frequently changing data (like many AMI IDs) outside the template (for example, in SSM Parameter Store or a configuration management system) if they change often.
Summary
- Mappings are static, table-like sections in a CloudFormation template defined under the top-level Mappings key.
- Use !FindInMap (short) or Fn::FindInMap (long) to look up values by mapping name, top-level key, and second-level key.
- Mapping values must be literal constants—no intrinsic functions or parameter references inside the Mappings block.
- Use mappings for predictable, template-time configuration such as region -> AMI mappings or account-specific settings.
Links and references
- AWS CloudFormation: Mappings
- AWS CloudFormation Intrinsic Functions: Fn::FindInMap
- AWS CloudFormation User Guide