edit-icon download-icon

Mappings

Last Updated: May 18, 2018

A mapping is a key-value mapping table. In the Resources and Outputs of a template, you can use the built-in function Fn::FindInMap to obtain the mapping table value by providing the key.

Syntax

A mapping consists of key-value pairs, where the key and value can be strings or numbers. If you define multiple mappings, separate them with commas (,). The name of each mapping must be unique.

Examples

The following example shows a correct mapping.

  1. "Mappings" : {
  2. "ValidMapping" : {
  3. "TestKey1" : { "TestValu1" : "value1" },
  4. "TestKey2" : { "TestValu2" : "value2" },
  5. 1234567890 : { "TestValu3" : "value3" },
  6. "TestKey4" : { "TestValu4" : 1234 }
  7. }
  8. }

The following example shows an incorrect mapping.

  1. "Mappings" : {
  2. "InvalidMapping1" : {
  3. "ValueList" : [ "foo", "bar" ],
  4. "ValueString" : "baz"
  5. },
  6. "InvalidMapping2": [ "foo", { "bar" : "baz" } ],
  7. "InvalidMapping3": "foobar"
  8. }

The following example shows how to use the built-in function Fn::FindInMap to obtain the mapping table value.

  1. {
  2. "ROSTemplateFormatVersion": "2015-09-01",
  3. "Parameters": {
  4. "regionParam": {
  5. "Description": "Select a region to create an ECS instance".
  6. "Type": "String",
  7. "AllowedValues": ["hangzhou", "beijing"]
  8. }
  9. },
  10. "Mappings" : {
  11. "RegionMap" : {
  12. "hangzhou" : { "32" : "m-25l0rcfjo", "64" : "m-25l0rcfj1" },
  13. "beijing" : { "32" : "m-25l0rcfj2", "64" : "m-25l0rcfj3" }
  14. }
  15. },
  16. "Resources": {
  17. "WebServer": {
  18. "Type": "ALIYUN::ECS::Instance",
  19. "Properties": {
  20. "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "regionParam" }, "32"]},
  21. "InstanceType": "ecs.t1.small",
  22. "SecurityGroupId": "sg-25zwc3se0",
  23. "ZoneId": "cn-beijing-b",
  24. "Tags": [{
  25. "Key": "Department1",
  26. "Value": "HumanResource"
  27. },{
  28. "Key": "Department2",
  29. "Value": "Finance"
  30. }
  31. ]
  32. }
  33. }
  34. }
  35. }
Thank you! We've received your feedback.