aws-step-functions-data-science-sdk-python
aws-step-functions-data-science-sdk-python copied to clipboard
`stepfunctions.steps.states.State.output()` doesn't seem to respect result_path
Hello,
there seems to be an issue if stepfunctions.steps.states.State.output() is used together with result_path. For example:
lambda_state_first = LambdaStep(
state_id="MyFirstLambdaStep",
parameters={
"FunctionName": "MakeApiCall",
"Payload": {
"input": "20192312"
}
},
result_path="$.NewOutputPath"
)
lambda_state_first.output()["Payload"].to_jsonpath()
I would expect that the output is "$['NewOutputPath']['Payload']", but it's actually "$['Payload']". Is that expected behavior and if so, how is the correct way to use result_path together with output()?
Thanks!
One of the consequences of this issue is that there seems to be no particular way to use .output() with steps do not come one after the other.
Hi @simonloew and @alex , thank you for reaching out with these questions. I'll try and address them below:
When using result_path, the output of the state can combination of its input and the result. In the example you have described, the Lambda state's output could have additional keys besides just NewOutputPath. One such example is illustrated here. lambda_state_first.output() refers to the entire output from lambda_state_first state, and not just under the key referenced in result_path. Hence the behavior you see is expected. If you would like to refer to "$['NewOutputPath']['Payload']" , you can do so using lambda_state_first.output()["NewOutputPath"]["Payload"].
Regarding not being able to use .output() with steps that do not come one after another, Step Functions supports passing the output of a state only to its next state in the state machine.