Mappings

更新时间:
复制 MD 格式

The Mappings section defines static key-value lookup tables in a template. Use Fn::FindInMap in the Resources or Outputs section to retrieve a value from a two-level map declared here.

Syntax

The Mappings section contains key-value pairs. Keys must be strings. Values can be of the String, Number, Boolean, List, or Dictionary type. When declaring multiple mappings in JSON, separate them with commas (,). Each mapping name must be unique within the section.

Note
  • Mappings must be pure data and cannot contain functions.

  • We recommend that you do not define single-level maps in the Mappings section. Resource Orchestration Service (ROS) cannot query a value from a single-level map.

Mappings:
  ValidMap:
    '1234567890':
      TestValu3: value3
    TestKey1:
      TestValu1: value1
    TestKey2:
      TestValu2: value2
    TestKey4:
      TestValu4: 1234

Each field in the Mappings section has a specific role:

  • ValidMap — the mapping logical name, unique within the template.

  • TestKey1, TestKey2, TestKey4, '1234567890' — top-level keys (strings).

  • TestValu1: value1 — second-level key-value pairs. Fn::FindInMap looks up values at this level.

    Example

    The following template uses Fn::FindInMap to select an image ID based on a region parameter. The RegionMap mapping stores image IDs for two regions (hangzhou and beijing), each with '32' and '64' keys.

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      regionParam:
        Description: the region where you want to create the Elastic Compute Service (ECS) instance
        Type: String
        AllowedValues:
          - hangzhou
          - beijing
    Mappings:
      RegionMap:
        hangzhou:
          '32': m-25l0rcfjo
          '64': m-25l0rcfj1
        beijing:
          '32': m-25l0rcfj2
          '64': m-25l0rcfj3
    Resources:
      WebServer:
        Type: ALIYUN::ECS::Instance
        Properties:
          ImageId:
            Fn::FindInMap:
              - RegionMap
              - Ref: regionParam
              - '32'
          InstanceType: ecs.t1.small
          SecurityGroupId: sg-25zwc****
          ZoneId: cn-beijing-b
          Tags:
            - Key: Department1
              Value: HumanResource
            - Key: Department2
              Value: Finance
                        

    Fn::FindInMap takes three arguments: the mapping name (RegionMap), the top-level key (resolved at deploy time from regionParam), and the second-level key ('32').

FAQ

You cannot query a value from a single-level map defined in the Mappings section. For more information, see How to query a value from a map in a template?