AWS Step Functions Input/Result/Output Paths

Quick reminder:

By default, a Step Function will take the output from previous task/lambda and give it to the next, so unless you want to specify how to handle the model in a particular way you don’t need to use these properties.

But if you need to, you’ve got:

InputPath

Will set what part of the current model should be given to the current Task. By default the entire model is given to the Task/Lambda.

ResultPath

In case you want to keep the model you had but still include the just finished tasks’ result in it, you can use this to set where inside that object the result will be set. By default the result of the Task/Lambda replaces the model. If set as null the task’s result will be ignored and the state model kept as it was.

OutputPath

Sets what part of the current state is given to the next Task, by default all of it is given. Do notice that the difference between Result and Output is that Result allows you to modify the current model state by adding the task’s result into it, replacing or keeping. Instead, Output decides what part of the state model is sent towards the next step, which will also have its own “InputPath” to decide what to give to the lambda.

Examples

The $ symbol references the entire current state model, by default, all paths have that value, so this doesn’t do anything:

"Step1": {
   "Type": "Task",
   "Resource": "LambdaFunction1",
   "Next": "Step2",
   "InputPath": "$",
   "ResultPath": "$",
   "OutputPath": "$"
},

Using ResultPath: null, you can ignore the result given by the lambda, which will simply keep the state model as it was before executing it:

"Step1": {
   "Type": "Task",
   "Resource": "LambdaFunction1",
   "Next": "Step2",
   "ResultPath": null,
},

Using InputPath, you can also decide that this task only needs a certain value, but still keep the rest of the state model so we can use it later:

"Step1": {
   "Type": "Task",
   "Resource": "LambdaFunction1",
   "Next": "Step2",
   "InputPath": "$.Param1",
   "ResultPath": null
},
"Step2": {
   "Type": "Task",
   "Resource": "LambdaFunction2",
   "Next": "Step3",
   "InputPath": "$.Param2",
   "ResultPath": null
},

Using ResultPath, you could also save the result from Step1 into a property of the state model so Step2 can use it. The rest of the model remains the same, only that property changes.

"Step1": {
   "Type": "Task",
   "Resource": "LambdaFunction1",
   "Next": "Step2",
   "InputPath": "$.Param1",
   "ResultPath": "$.Step1Result"
},
"Step2": {
   "Type": "Task",
   "Resource": "LambdaFunction2",
   "Next": "Step3",
   "InputPath": "$.Step1Result",
   "ResultPath": null
},

Using OutputPath, you can clean the state model by only allowing a property to go through, following previous example, now Step2 just takes the entire state by default:

"Step1": {
   "Type": "Task",
   "Resource": "LambdaFunction1",
   "Next": "Step2",
   "InputPath": "$.Param1",
   "ResultPath": "$.Step1Result",
   "OutputPath": "$.Step1Result"
},
"Step2": {
   "Type": "Task",
   "Resource": "LambdaFunction2",
   "Next": "Step3"
},

Using mappers

Instead of paths, you can also map the state model using a mapper step. I haven’t used this but here’s the documentation.

Leave a Reply

Close Bitnami banner
Bitnami