Step Functions - how to join an array?

0

As of now there is a States.StringSplit($.inputString, $.splitter) intrinsic function to split an string into an array. Is there a way to join an array into an string? Something like States.ArrayJoin($.inputString, $.joiner)? Is there any work around to achieve something like that?

Reason is that I want to replace a character in a string, since there is no replace I thought about splitting and joining which does have the same effect. I'm using an activity and building an url with the taskToken, but unfortunately any "+" character get's replace by a space, so I want to replace it with "%2B".

Jonas
질문됨 9달 전796회 조회
2개 답변
1

Yes, but not easily. You can iterate through the array of items you want to join using a Choice that flows to a Pass that uses States.Format to append each array item to a string. It's ugly, but it works.

  1. Create a Pass state that initializes the string accumulator and the number of items in the array, and flow to the Choice state below: Parameters: { "the_string": "", "item_count.$": "$.States.ArrayLength($.my_array)", "current_index": 0, "my_array.$": "$.my_array" }
  2. Create a choice state that tests the array length and current index to see if any items remain to be appended: Choices: [ { "Variable": "$.current_index", "NumericLessThanPath": "$.item_count", "Next": "Append an Item" } ]
  3. Create a Pass state that appends the string and increments the current index, and returns to the Choice state above: Parameters: { "the_string.$": "States.Format('{}your seprator here{}', $.the_string, $. )", "item_count.$": "$.item_count", "current_index.$": "States.MathAdd($.current_index, 1)", "my_array.$":"$.my_array" }

The Choice state will flow to the default Next state once all of the array items have been appended to $.the_string.

Hope that's clear enough.

mlhpdx
답변함 8일 전
0

One option will be to use States.Format() and pass the array contents if the array length is fixed.

AWS
답변함 9달 전
  • Thanks, unfortunately the output of an taskToken does not have an constant number of "+". I already thought about a loop which combines always 2 array values as long as there are more than 1 value in the array. But for an Standard function that's also pretty expensive. Would be nice if there is a native function to achieve that.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠