I have a AWS Step Function State formatted as follows:
"MyState": { "Type": "Task", "Resource": "<MyLambdaARN>", "ResultPath": "$.value1" "Next": "NextState" }
I want to add a second value but can't find out how anywhere. None of the AWS examples display multiple ResultPath values being added to the output.
Would I just add a comma between them?
"MyState": { "Type": "Task", "Resource": "<MyLambdaARN>", "ResultPath": "$.value1, $.value2" "Next": "NextState" }
Or is there a better way to format these?
OutputPath enables you to select a portion of the state output to pass to the next state. This enables you to filter out unwanted information, and pass only the portion of JSON that you care about. If you don't specify an OutputPath the default value is $ .
Step Functions paths use JsonPath syntax. To specify that a parameter use a path to reference a JSON node in the input, end the parameter name with . $ . For example, if you have text in your state input in a node named message , you could pass that to a parameter by referencing the input JSON with a path.
It is a common use case when you need to call one remote service, based on its response create a second request and combine the first response with the second response.
Executing a step function Whatever the first state will receive these data as input. If the state is a Wait step it would automatically pass in the received data to the next state, but if it is a lambda you need to return it in the callback.
Let's answer this straight up: you can't specify multiple ResultPath
values, because it doesn't make sense. Amazon does do a pretty bad job of explaining how this works, so I understand why this is confusing.
You can, however, return multiple result values from a State in your State Machine.
General Details
The input to any State is a JSON object. The output of the State is a JSON object.
ResultPath
directs the State Machine what to do with the output (result) of the State. Without specifying ResultPath
, it defaults to $
which means all the input to the State is lost, replaced by the output of the State.
If you want to allow data from the input JSON to pass through your State, you specify a ResultPath
to describe a property to add/overwrite on the input JSON to pass to the next State.
Your scenario
In your case, $.value1
means the output JSON of your State is the input JSON with a new/overwritten property value1
containing the output JSON of your lambda.
If you want multiple values in your output, your lambda should return a JSON object containing the multiple values, which will be the value of the value1
property.
If you don't care about allowing input values passing through your State, leave the ResultPath
as the default $
by omitting it. The output JSON containing your multiple values will be the input to the next State.
Support scenario
Here's a simple State machine I use to play with the inputs and outputs:
{ "StartAt": "State1", "States": { "State1": { "Type": "Pass", "Result": { "Value1": "Yoyo", "Value2": 1 }, "ResultPath": "$.Result", "Next": "State2" }, "State2": { "Type": "Pass", "Result": { "Value2": 5 }, "ResultPath": "$.Result", "Next": "State3" }, "State3": { "Type": "Pass", "Result": "Done", "End": true } } }
Execute this with the following input:
{ "Input 1": 10000, "Input 2": "YOLO", "Input 3": true }
Examine the inputs and outputs of each Stage. You should observe the following:
ResultPath
always directs output to a Result
property of the input.State1
is overwritten by the Output of State2
. The net effect is Result.Value1
disappears and Result.Value2
is "updated".Hopefully this clarifies how to use ResultPath
effectively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With