💾 Archived View for cfdocs.wetterberg.nu › intrinsic-function-reference-split.gemini captured on 2021-12-03 at 14:04:38. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Fn::Split

Search

To split a string into a list of string values so that you can select an element from the resulting string list, use the `Fn::Split` intrinsic function. Specify the location of splits with a delimiter, such as `,` (a comma). After you split a string, use the Fn::Select function to pick a specific element.

Fn::Select

For example, if a comma-delimited string of subnet IDs is imported to your stack template, you can split the string at each comma. From the list of subnet IDs, use the `Fn::Select` intrinsic function to specify a subnet ID for a resource.

Declaration

JSON

{ "Fn::Split" : [ "delimiter", "source string" ] }

YAML

Syntax for the full function name:

Fn::Split: [ delimiter, source string ]

Syntax for the short form:

!Split [ delimiter, source string ]

Parameters

You must specify both parameters.

delimiter

A string value that determines where the source string is divided.

source string

The string value that you want to split.

Return value

A list of string values.

Examples

The following examples demonstrate the behavior of the `Fn::Split` function.

Simple list

The following example splits a string at each vertical bar (`|`). The function returns `["a", "b", "c"]`.

JSON

1. { "Fn::Split" : [ "|" , "a|b|c" ] }

YAML

1. !Split [ "|" , "a|b|c" ]

 

List with empty string values

If you split a string with consecutive delimiters, the resulting list will include an empty string. The following example shows how a string with two consecutive delimiters and an appended delimiter is split. The function returns `["a", "", "c", ""]`.

JSON

1. { "Fn::Split" : [ "|" , "a||c|" ] }

YAML

1. !Split [ "|" , "a||c|" ]

 

Split an imported output value

The following example splits an imported output value, and then selects the third element from the resulting list of subnet IDs, as specified by the `Fn::Select` function.

JSON

1. { "Fn::Select" : [ "2", { "Fn::Split": [",", {"Fn::ImportValue": "AccountSubnetIDs"}]}] }

YAML

1. !Select [2, !Split [",", !ImportValue AccountSubnetIDs]]

Supported functions

For the `Fn::Split` delimiter, you cannot use any functions. You must specify a string value.

For the `Fn::Split` list of values, you can use the following functions: