Fn::Length returns the length of an object, such as the number of characters in a string, elements in a list, or key-value pairs in a dictionary.
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 whose length you want to obtain. Valid types: String, List, and Dictionary.
Return value
The length of the object. The return value is an integer.
Examples
Calculate the number of key-value pairs in a dictionary
!Length
key1: v1
key2: v2{
"Fn:Length": {
"key1": "v1",
"key2": "v2"
}
}The return value is 2.
Calculate the number of elements in a list
!Length
- 1
- 2
- 3{
"Fn:Length": [1,2,3]
}The return value is 3.
Calculate the number of characters in a string
!Length aaaaaa{
"Fn::Length": "aaaaaa"
}The return value is 6.