从 Choice 状态传递输入的问题
Problem in passing inputs from Choice state
我正在 Step Function 上做一些实验,所以我设计了这个工作流程。
here is the workflow snapshot
代码:
{
"Comment": "SF demo",
"StartAt": "Map",
"States": {
"Map": {
"Type": "Map",
"InputPath": "$.Records",
"ItemsPath": "$.payload",
"MaxConcurrency": 2,
"Parameters":{
"input1.$":"$.choice1",
"input2.$":"$.choice2"
},
"Next": "Final State",
"Iterator": {
"StartAt": "ChoiceState",
"States": {
"ChoiceState": {
"Type": "Choice",
"Choices":[
{
"Variable":"$.input1",
"StringEquals":"input1",
"Next":"CWT"
},
{
"Variable":"$.input2",
"StringEquals":"input2",
"Next":"Lenel"
}
]
},
"CWT":{
"Type":"Task",
"InputPath":"$.payload",
"Resource":"***********************",
"End": true
},
"Lenel":{
"Type":"Task",
"Resource":"****************",
"End": true
}
}
}
},
"Final State": {
"Type": "Pass",
"End": true
}
}
}
我在处理输入时遇到问题
我将有这种类型的输入:
{
"Records": {
"choice1": "input1",
"choice2": "input2",
"payload": [
{
"Key": "tempfile1.csv"
}
]
}
}
我的期望:选择状态将读取数据 "choice1" 和 "choice2" 并将转换到下一个状态,其中将处理 "payload" 数据数组。
但是 "Payload" 数据没有传递到下一个状态,我遇到了这个问题
TaskStateEntered CWT - 238 Mar 18, 2020 12:15:57.070 PM
{
"name": "CWT",
"input": {
"input2": "input2",
"input1": "input1"
}
}
ExecutionFailed - 238 Mar 18, 2020 12:15:57.070 PM
{
"error": "States.Runtime",
"cause": "An error occurred while executing the state 'CWT' (entered at the event id #7).
Invalid path
'$.payload' : No results for path: $['payload']"
}
由于您在地图状态中指定了 "Parameters",因此输入会按照 docs:
中指定的方式被覆盖
"The input to each iteration, by default, is a single element of the
array field identified by the ItemsPath value, This may be overridden
using the Parameters field."
因此,要解决此问题,您需要使用映射状态的 context object 重新映射参数中的 "payload" 键。这是您的状态机示例,其中 "payload" 键已重新映射:
{
"Comment": "SF demo",
"StartAt": "Map",
"States": {
"Map": {
"Type": "Map",
"InputPath": "$.Records",
"ItemsPath": "$.payload",
"MaxConcurrency": 2,
"Parameters": {
"input1.$": "$.choice1",
"input2.$": "$.choice2",
"payload.$": "$$.Map.Item.Value"
},
"Next": "Final State",
"Iterator": {
"StartAt": "ChoiceState",
"States": {
"ChoiceState": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.input1",
"StringEquals": "input1",
"Next": "CWT"
},
{
"Variable": "$.input2",
"StringEquals": "input2",
"Next": "Lenel"
}
]
},
"CWT": {
"Type": "Pass",
"InputPath": "$.payload",
"End": true
},
"Lenel": {
"Type": "Pass",
"InputPath": "$.payload",
"End": true
}
}
}
},
"Final State": {
"Type": "Pass",
"End": true
}
}
}
我正在 Step Function 上做一些实验,所以我设计了这个工作流程。 here is the workflow snapshot
代码:
{
"Comment": "SF demo",
"StartAt": "Map",
"States": {
"Map": {
"Type": "Map",
"InputPath": "$.Records",
"ItemsPath": "$.payload",
"MaxConcurrency": 2,
"Parameters":{
"input1.$":"$.choice1",
"input2.$":"$.choice2"
},
"Next": "Final State",
"Iterator": {
"StartAt": "ChoiceState",
"States": {
"ChoiceState": {
"Type": "Choice",
"Choices":[
{
"Variable":"$.input1",
"StringEquals":"input1",
"Next":"CWT"
},
{
"Variable":"$.input2",
"StringEquals":"input2",
"Next":"Lenel"
}
]
},
"CWT":{
"Type":"Task",
"InputPath":"$.payload",
"Resource":"***********************",
"End": true
},
"Lenel":{
"Type":"Task",
"Resource":"****************",
"End": true
}
}
}
},
"Final State": {
"Type": "Pass",
"End": true
}
}
}
我在处理输入时遇到问题
我将有这种类型的输入:
{
"Records": {
"choice1": "input1",
"choice2": "input2",
"payload": [
{
"Key": "tempfile1.csv"
}
]
}
}
我的期望:选择状态将读取数据 "choice1" 和 "choice2" 并将转换到下一个状态,其中将处理 "payload" 数据数组。
但是 "Payload" 数据没有传递到下一个状态,我遇到了这个问题
TaskStateEntered CWT - 238 Mar 18, 2020 12:15:57.070 PM
{
"name": "CWT",
"input": {
"input2": "input2",
"input1": "input1"
}
}
ExecutionFailed - 238 Mar 18, 2020 12:15:57.070 PM
{
"error": "States.Runtime",
"cause": "An error occurred while executing the state 'CWT' (entered at the event id #7).
Invalid path
'$.payload' : No results for path: $['payload']"
}
由于您在地图状态中指定了 "Parameters",因此输入会按照 docs:
中指定的方式被覆盖"The input to each iteration, by default, is a single element of the array field identified by the ItemsPath value, This may be overridden using the Parameters field."
因此,要解决此问题,您需要使用映射状态的 context object 重新映射参数中的 "payload" 键。这是您的状态机示例,其中 "payload" 键已重新映射:
{
"Comment": "SF demo",
"StartAt": "Map",
"States": {
"Map": {
"Type": "Map",
"InputPath": "$.Records",
"ItemsPath": "$.payload",
"MaxConcurrency": 2,
"Parameters": {
"input1.$": "$.choice1",
"input2.$": "$.choice2",
"payload.$": "$$.Map.Item.Value"
},
"Next": "Final State",
"Iterator": {
"StartAt": "ChoiceState",
"States": {
"ChoiceState": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.input1",
"StringEquals": "input1",
"Next": "CWT"
},
{
"Variable": "$.input2",
"StringEquals": "input2",
"Next": "Lenel"
}
]
},
"CWT": {
"Type": "Pass",
"InputPath": "$.payload",
"End": true
},
"Lenel": {
"Type": "Pass",
"InputPath": "$.payload",
"End": true
}
}
}
},
"Final State": {
"Type": "Pass",
"End": true
}
}
}