All Products
Search
Document Center

Resource Orchestration Service:Fn::Length

Last Updated:Mar 15, 2024

The built-in function Fn::Length returns the number of elements in an object.

Declaration

  • JSON

    {
     "Fn::Length": Object
    }
  • YAML

    • Syntax for the full function name:

      Fn::Length : Object
    • Syntax for the short form:

      !Length Object

Parameters

Object: the object in which you want to calculate the number of elements. The object supports the String, List, or Dictionary type.

Return value

The number of elements in the object. The value is of the Integer type.

Examples

Calculate the number of key-value pairs in a dictionary

!Length
  key1: v1
  key2: v2
{
  "Fn:Length": {
    "key1": "v1",
    "key2": "v2"
  }
}

In this example, 2 is returned.

Calculate the number of elements in a list

!Length
 - 1
 - 2
 - 3
{
  "Fn:Length": [1,2,3]
}

In this example, 3 is returned.

Calculate the number of characters in a string

!Length aaaaaa
{
  "Fn::Length": "aaaaaa"
}

In this example, 6 is returned.