Mappings Section
What you'll learn: How to create lookup tables in CloudFormation to store and retrieve static configuration values organized by region, environment, or other keys.
What Are Mappings?
The Mappings section in CloudFormation lets you define a two-level lookup table of static values. Think of it as a reference chart—like choosing paint colors based on room type and lighting conditions. You define categories (first-level keys) and subcategories (second-level keys), then use intrinsic functions to retrieve the exact value you need.
Why Use Mappings?
When deploying infrastructure across multiple regions or environments, certain values change predictably. Instead of creating separate templates or asking users to enter AMI IDs manually via Parameters, you embed these known values in a structured map.
Example use cases:
- Region-specific AMI IDs for EC2 instances
- Environment-specific instance types (dev uses t2.micro, prod uses m5.large)
- CIDR blocks per region
Structure
Mappings:
RegionMap:
us-east-1:
AMI: ami-0abcdef1234567890
eu-west-1:
AMI: ami-9876543210fedcba0
This creates a mapping named RegionMap with region keys, each containing an AMI property.
Retrieving Values
You use Fn::FindInMap (covered in your next lessons) to look up values:
ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", AMI]
This reads: "In RegionMap, find the current region's AMI value."
Key Takeaway: Mappings store static lookup tables with two-level keys, making templates cleaner and region/environment-aware without user input.