Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Fn::Length

Focus mode
Fn::Length - AWS CloudFormation
Filter View

The intrinsic function Fn::Length returns the number of elements within an array or an intrinsic function that returns an array.

Important

You must use the AWS::LanguageExtensions transform to use the Fn::Length intrinsic function.

Declaration

JSON

{ "Fn::Length" : IntrinsicFunction }
{ "Fn::Length" : Array }

YAML

Fn::Length : IntrinsicFunction
Fn::Length : Array

Parameters

IntrinsicFunction

The intrinsic function that returns an array that you want to return a number of elements from.

Array

The array you want to return the number of elements from.

Return value

The number of elements in the intrinsic function that returns an array or in the array passed to the intrinsic function.

Examples

Return the number of elements in an intrinsic function that returns an array

This example snippet returns the number of elements in an intrinsic function that returns an array. The function returns 3.

JSON

{ //... "Transform": "AWS::LanguageExtensions" //... "Fn::Length" : { "Fn::Split": ["|", "a|b|c"] } //... }

YAML

Transform: 'AWS::LanguageExtensions' #... Fn::Length: !Split ["|", "a|b|c"] #...

Return the number of elements in a Ref intrinsic function that refers to a list parameter type

This example snippet returns the number of elements in a Ref intrinsic function that refers to a list parameter type. If the parameter with the name ListParameter is a list with 3 elements, the function returns 3.

JSON

{ //... "Transform": "AWS::LanguageExtensions" //... "Fn::Length": { "Ref": "ListParameter" } //... }

YAML

Transform: 'AWS::LanguageExtensions' #... Fn::Length: !Ref ListParameter #...

Return the number of elements in an array

This example snippet returns the number of elements in the array passed to the intrinsic function. The function returns 3.

JSON

{ //... "Transform": "AWS::LanguageExtensions" //... "Fn::Length": [ 1, {"Ref": "ParameterName"}, 3 ] //... }

YAML

Transform: 'AWS::LanguageExtensions' #... Fn::Length: - 1 - !Ref ParameterName - 3 #...

Supported functions

You can use the following functions in the Fn::Length intrinsic function or array:

  • Condition Functions

  • Fn::Base64

  • Fn::FindInMap

  • Fn::Join

  • Fn::Length

  • Fn::Select

  • Fn::Split

  • Fn::Sub

  • Fn::ToJsonString

  • Ref

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.