Search code examples
amazon-web-servicesaws-step-functions

Passthrough input to output in AWS Step Functions


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.


Solution

  • 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"
    }