Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

Fn::Split

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.

Declaration

JSON

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

YAML

Syntax for the full function name:

Copy
Fn::Split: [ delimiter, source string ]

Syntax for the short form:

Copy
!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

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

YAML

Copy
!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

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

YAML

Copy
!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

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

YAML

Copy
!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:

  • Fn::Base64

  • Fn::FindInMap

  • Fn::GetAtt

  • Fn::GetAZs

  • Fn::If

  • Fn::Join

  • Fn::Select

  • Ref