All Products
Search
Document Center

Resource Orchestration Service:Fn::Index

Last Updated:Mar 15, 2024

The built-in function Fn::Index queries the index of an element in a list.

Declaration

  • JSON

    {
      "Fn::Index": [
        "item_to_find_index",
        [
        	"item1",
          "item2",
          ...
     		]
      ]
    }
  • YAML

    • Syntax for the full function name:

      Fn::Index:
       - item_to_find_index
       - - item1
         - item2
         - ...
    • Syntax for the short form:

      !Index [item_to_find_index, [item1, item2, ...]]

Parameters

  • item_to_find_index: the element whose index you want to query. If the element does not exist in the list, an empty string is returned.

  • item: the element in the list.

Return value

The index of the element in the list. If the element does not exist, an empty string is returned.

Examples

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ZoneIds:
    Type: Json
    Default:
      - cn-beijing-a
      - cn-beijing-b
      - cn-beijing-f
  ZoneId:
    Type: String
    Default: cn-beijing-b
Outputs:
  Index:
    Value: !Index [!Ref ZoneId, !Ref ZoneIds]
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "ZoneIds": {
      "Type": "Json",
      "Default": [
        "cn-beijing-a",
        "cn-beijing-b",
        "cn-beijing-f"
      ]
    },
    "ZoneId": {
      "Type": "String",
      "Default": "cn-beijing-b"
    }
  },
  "Outputs": {
    "Index": {
      "Value": {
        "Fn::Index": [
          {
            "Ref": "ZoneId"
          },
          {
            "Ref": "ZoneIds"
          }
        ]
      }
    }
  }
}

Supported functions

For the element whose index you want to query by using the Fn::Index function, you can use the Ref function.

For the Fn::Index list of objects, you can use the following functions: