I am doing some kind experiment on Step Function so I have designed this workflow. here is the workflow snapshot
Code:
{
"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
}
}
}
I am facing problem in processing inputs
I will have inputs of this type:
{
"Records": {
"choice1": "input1",
"choice2": "input2",
"payload": [
{
"Key": "tempfile1.csv"
}
]
}
}
My expectation: choice state will read data "choice1" and "choice2" and will transist to next state where array of "payload" data will process.
But "Payload" data is not passing to next state and I am getting this issue
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']"
}
Since you are specifying "Parameters" in your Map State the input gets overridden as specified in the 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."
Therefore to fix this, you will need to remap the "payload" key in Parameters by using the context object for Map States. Here is an example of your State Machine with the "payload" key remapped:
{
"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
}
}
}