CloudFormation Mappings Overview
- Purpose of Mappings: Mappings are used to define fixed variables within CloudFormation templates. They are particularly useful for differentiating between environments (e.g., dev vs. prod) or settings that vary based on certain conditions (e.g., AWS regions, AMI types).
- Contain hardcoded values within the template.
- Characteristics of Mappings:
- Are ideal for values that change based on known variables, such as region or environment.
Format of Mappings
- Mappings are defined in a specific format within the CloudFormation template.
- They are structured as a map of key-value pairs.
Example: Region Map
- Purpose: To provide different AMI IDs based on the AWS region and architecture type.
- Structure:
- Keys represent AWS regions (e.g.,
us-east-1, us-west-1, eu-west-1).
- Nested keys represent architecture types (e.g.,
HVM64, HVMG2).
- Values are the corresponding AMI IDs for each region-architecture combination.

When to Use Mappings vs. Parameters
- Mappings:
- Suitable for predefined, predictable values.
- Offer safer control over template variables.
- Depend on known factors like region, AZ, AWS account, or environment.
- Parameters:
- Ideal for values that depend on user input at runtime.
- Provide users with flexibility and freedom to specify values.
Conclusion
- Mappings are a powerful feature in CloudFormation for managing environment-specific or region-specific values.
- They should be used when the possible values are known in advance and can be determined from other variables.
- Parameters should be used when user input is required to determine the value at the time of stack creation or update.