Fn::MergeMapToList

更新时间:
复制 MD 格式

Fn::MergeMapToList merges multiple source mappings into a list of mappings, combining values by position.

Declaration

  • JSON

    {
      "Fn::MergeMapToList": [
        {
          "key_1": ["key_1_item_1", "key_1_item_2", ...]
        },
        {
          "key_2": ["key_2_item_1", "key_2_item_2", ...],
        },
        ...
      ]
    }
  • YAML

    • Syntax for the full function name:

      Fn::MergeMapToList:
        - key_1:
            - key_1_item_1
            - key_1_item_2
            - ...
        - key_2:
            - key_2_item_1
            - key_2_item_2
            - ...
        - ...
    • Syntax for the short form:

      !MergeMapToList [{key_1: [key_1_item_1, key_1_item_2, ..]}, {key_2: [key_2_item_1, key_2_item_2, ...]}, ...]

Parameters

[{key_1: [key_1_item_1, key_1_item_2, ..]}, {key_2: [key_2_item_1, key_2_item_2, ...]},...]: the source mappings. Each source mapping must have a list of values.

The merge follows these rules:

  1. The key and the first value in each source mapping are merged into the first mapping in the list.

  2. The key and the second value are merged into the second mapping, and so on for subsequent values.

  3. The resulting list length equals the largest value count among all source mappings. If source mappings have different numbers of values, the last value of a shorter mapping is repeated to fill the remaining positions.

Return value

The list of merged mappings.

Syntax examples

  • Three source mappings with the same number of values:

    Fn::MergeMapToList:
      - key_1:
          - key_1_item_1
          - key_1_item_2
      - key_2:
          - key_2_item_1
          - key_2_item_2
      - key_3:
          - key_3_item_1
          - key_3_item_2

    Result:

    - key_1: key_1_item_1
      key_2: key_2_item_1
      key_3: key_3_item_1
    - key_1: key_1_item_2
      key_2: key_2_item_2
      key_3: key_3_item_2
  • Three source mappings with different numbers of values:

    Fn::MergeMapToList:
      - key_1:
          - key_1_item_1
          - key_1_item_2
      - key_2:
          - key_2_item_1
          - key_2_item_2
          - key_2_item_3
      - key_3:
          - key_3_item_1
          - key_3_item_2

    Result:

    - key_1: key_1_item_1
      key_2: key_2_item_1
      key_3: key_3_item_1
    - key_1: key_1_item_2
      key_2: key_2_item_2
      key_3: key_3_item_2
    - key_1: key_1_item_2
      key_2: key_2_item_3
      key_3: key_3_item_2

Usage example

The following template adds all instances created by WebServer to the server group of a Server Load Balancer (SLB) instance:

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  WebServer:
    Type: ALIYUN::ECS::InstanceGroupClone
    Properties:
      SourceInstanceId: i-xxxxx
      Password: Hello****
      MinAmount: 1
      MaxAmount: 1
  CreateVServerGroup:
    Type: ALIYUN::SLB::VServerGroup
    Properties:
      LoadBalancerId: lb-****
      VServerGroupName: VServerGroup-****
      BackendServers:
        !MergeMapToList
          - Port:
              - 6666
              - 9090
              - 8080
          - ServerId: !GetAtt WebServer.InstanceIds
          - Weight:
              - 20
              - 100

Supported functions