Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 979
matsev Avatar asked Dec 05 '17 10:12

matsev


People also ask

What is output path in step function?

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 $ .

What is pass in AWS?

A Pass state ( "Type": "Pass" ) passes its input to its output, without performing work. Pass states are useful when constructing and debugging state machines. In addition to the common state fields, Pass states allow the following fields. Result (Optional)

What performs the work in a workflow when using AWS Step Functions?

The activity worker polls Step Functions for work, takes any inputs from Step Functions, performs the work using your code, and returns results.


2 Answers

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"
}
like image 144
matsev Avatar answered Oct 22 '22 17:10

matsev


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

like image 28
Alex Avatar answered Oct 22 '22 17:10

Alex