23

How can I passthrough the input to a Task state in an AWS Step Functions to the output?

After reading the Input and Output Processing page in the AWS docs, I have played with various combinations of InputPath, ResultPath and OutputPath.

State definition:

"First State": {
    "Type": "Task",
    "Resource": "[My Lambda ARN]",
    "Next": "Second State",
    "InputPath": "$.someKey",
    "OutputPath": "$"
}

Input:

{
    "someKey": "someValue"
}

Expected Result

I would like the output of the First State (and thus the input of Second State) to be

{
    "someKey": "someValue"
}

Actual Result

[empty]

What if the input is more complicated, e.g.

{
    "firstKey": "firstValue",
    "secondKey": "secondValue"
}

I would like to forward all of it without worrying about (sub) paths.

1
  • Hello, @matsev. Can you please answer my question? It is similar to what you asked. Thanks Commented Oct 11, 2019 at 17:13

4 Answers 4

43

In the Amazon States Language spec it is stated that:

If the value of ResultPath is null, that means that the state’s own raw output is discarded and its raw input becomes its result.

Consequently, I updated my state definition to

"First State": {
    "Type": "Task",
    "Resource": "[My Lambda ARN]",
    "Next": "Second State",
    "ResultPath": null
}

As a result, when passing the input example Task input payload will be copied to the output, even for rich objects like:

{
    "firstKey": "firstValue",
    "secondKey": "secondValue"
}
Sign up to request clarification or add additional context in comments.

Comments

13

For those who find themselves here using CDK, the solution is to use the explicit aws_stepfunctions.JsonPath.DISCARD enum rather than None/null.

from aws_cdk import (
    aws_stepfunctions,
    aws_stepfunctions_tasks,
)

aws_stepfunctions_tasks.LambdaInvoke(
    self,
    "my_function",
    lambda_function=lambda_function,
    result_path=aws_stepfunctions.JsonPath.DISCARD,
)

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-stepfunctions.JsonPath.html#static-discard

Comments

2

For those who don't want to just pass input to output but to add result of Task to input and forward all of it as output you can use "ResultPath": "$.addedOutput" as described in https://docs.aws.amazon.com/step-functions/latest/dg/input-output-resultpath.html

Comments

-2

I was looking for a solution from passing input from one parallel state to another parallel state and the above option worked really good. For example my step function is like this...tas1->parallel task2 -> parallel trask3 -> task4. So when it start with parallel task3, the input values are wiped out, so ptask3 is failing. With the above option, i was able to pass in same input from ptask2 to ptas3.

1 Comment

Hi spatel, this isn't an answer in it's own right, more of a comment on the answer you are referring to. Please delete this Answer and post as a comment on the matsev answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.