- Place the Mappings section near the top of the template (it’s common to declare Parameters and Mappings before Resources for readability).
- Give the mapping a name (in this example: DevMap).
- Under that name, define top-level keys (here: Arno and Alice).
- For each key, include one or more named values (here: Field with a string value).
- Because the mapping keys match the allowed parameter values for InputDeveloperName, you can reference the mapping based on the selected parameter value.
- Use mappings for static configuration (region, environment, role, AMI IDs) to keep templates DRY and easier to maintain.
- Keep mapping keys synchronized with Parameter AllowedValues when you want controlled, predictable lookups.
- Prefer !FindInMap for lookups instead of long conditionals or repeated parameters.
| Feature | Use case | Example |
|---|---|---|
| Mappings | Static lookups keyed by known values | Region-to-AMI mapping, developer role lookup |
| Parameters | User-supplied inputs or constrained values | Bucket names, allowed developer names |
| Conditions | Deploy resources conditionally based on parameters or mappings | Create resources only in certain environments |
If you run cfn-lint you may see a message like “Mapping ‘DevMap’ is defined but not used.” This is expected until you reference the mapping with !FindInMap in your template. Running a dry validation (aws cloudformation validate-template) or using a lint rule that checks references can help confirm correct usage.
- AWS CloudFormation intrinsic functions: Fn::FindInMap
- CloudFormation template anatomy and best practices
- cfn-lint GitHub repository