我在中间 AWS Step 函数状态下有如下所示的数组输入,我想将其连接到单个字符串中,我知道
States.StringSplit
用于将带有分隔符的字符串拆分为数组,可以使用 内在函数 进行反向操作,而无需编写lambda 函数?
例如:输入参数为:
{
"inputArray": ["a","b","c"],
"joiner": "/"
}
我期待以下结果路径:
{"joinedValue": "a/b/c/"}
或者
{"joinedValue": "a/b/c"}
您可以使用步骤函数而不使用 lambda 来完成此操作,但这不是一个步骤 - 您需要一个循环将所有部分组合成一个字符串:
JoinArray:
id: JoinArrayStateMachine
name: ${self:service}-${self:provider.stage}-JoinArrayStateMachine
type: EXPRESS
definition:
Comment: Join Array Orchestration
Version: "1.0"
StartAt: Make Input
States:
Make Input:
Type: Pass
Parameters:
inputArray.$: States.StringSplit('a,b,c',',')
joiner: /
Next: Get First Item
Get First Item:
Type: Pass
Parameters:
index: 1
increment: 1
item.$: States.ArrayGetItem($.inputArray, 0)
length.$: States.ArrayLength($.inputArray)
ResultPath: $.iterator
Next: Check Joined Items Length
Check Joined Items Length:
Type: Choice
Choices:
- Variable: $.joinedValue
IsPresent: false
Next: Create Joined Items
- Variable: $.joinedValue
StringEquals: ''
Next: Create Joined Items
Default: Append Joined Items
Create Joined Items:
Type: Pass
Parameters:
iterator.$: $.iterator
inputArray.$: $.inputArray
joiner.$: $.joiner
joinedValue.$: $.iterator.item
Next: Check Index
Append Joined Items:
Type: Pass
Parameters:
iterator.$: $.iterator
inputArray.$: $.inputArray
joiner.$: $.joiner
joinedValue.$: States.Format('{}{}{}',$.joinedValue,$.joiner,$.iterator.item)
Next: Check Index
Check Index:
Type: Choice
Choices:
- Variable: $.iterator.length
NumericGreaterThanPath: $.iterator.index
Next: Get Next Item
Default: Finish
Get Next Item:
Type: Pass
Parameters:
index.$: States.MathAdd($.iterator.index, $.iterator.increment)
increment.$: $.iterator.increment
item.$: States.ArrayGetItem($.inputArray, $.iterator.index)
length.$: States.ArrayLength($.inputArray)
ResultPath: $.iterator
Next: Check Joined Items Length
Finish:
Type: Pass
Parameters:
iterator: ()
inputArray.$: $.inputArray
joiner.$: $.joiner
joinedValue.$: $.joinedValue
Next: End
End:
Type: Succeed