💾 Archived View for cfdocs.wetterberg.nu › intrinsic-function-reference-split.gemini captured on 2024-05-10 at 12:43:48. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-12-03)
-=-=-=-=-=-=-
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.
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.
{ "Fn::Split" : [ "delimiter", "source string" ] }
Syntax for the full function name:
Fn::Split: [ delimiter, source string ]
Syntax for the short form:
!Split [ delimiter, source string ]
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.
A list of string values.
The following examples demonstrate the behavior of the `Fn::Split` function.
The following example splits a string at each vertical bar (`|`). The function returns `["a", "b", "c"]`.
1. { "Fn::Split" : [ "|" , "a|b|c" ] }
1. !Split [ "|" , "a|b|c" ]
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", ""]`.
1. { "Fn::Split" : [ "|" , "a||c|" ] }
1. !Split [ "|" , "a||c|" ]
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.
1. { "Fn::Select" : [ "2", { "Fn::Split": [",", {"Fn::ImportValue": "AccountSubnetIDs"}]}] }
1. !Select [2, !Split [",", !ImportValue AccountSubnetIDs]]
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: