All Products
Search
Document Center

Resource Orchestration Service:Mappings

Last Updated:Mar 20, 2024

The Mappings section matches a key to a corresponding set of named values. In the Resources and Outputs sections of a template, you can invoke the Fn::FindInMap built-in function to query the value that corresponds to keys in a two-level map declared in the Mappings section.

Syntax

The Mappings section contains key-value pairs. Keys are of the String type. Values are of the String, Number, Boolean, List, or Dictionary type. If you declare multiple mappings in JSON, separate the mappings with commas (,). Each mapping name must be unique.

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

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

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

Example

The following example shows how to use Fn::FindInMap to query the return value:

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
                    

FAQ

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