Mappings

  • For CloudFormation to declare fixed values. Handy when working with different environments (dev vs prod, regions)
  • Example
Mappings:
	Mapping01:
		Key01:
			Name: "value1"
		Key02:
			Name: "value2"
		Key03:
			Name: "value3"
	RegionMap:
		us-east-1:
			"32": "..."
			"64": "..."
		us-west-1:
			"32": "..."
			"64": "..."
		eu-east-1:
			"32": "..."
			"64": "..."

Mappings vs Parameters

  • Use Mapping when you know ahead what will be the values of the field
  • Use Parameters if it's more user-specific

Fn::FindInMap

  • To find the value in a mappings
  • Syntax: !FindInMap[MapName, TopLevelKey, SecondLevelKey]
  • For example
Resources:
	ec2Instance:
		Type: "AWS::EC2::Instance"
		Properties:
			ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", 32]