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

How to pass different output from Choice state in AWS Step Function?


Let say part of my Step Function looks like next:

"ChoiceStateX": {
  "Type": "Choice",
  "Choices": [
    {
      "Variable": "$.value",
      "NumericEquals": 0,
      "Next": "ValueIsZero"
    }
  ],
  "Default": "DefaultState"
},
"ValueIsZero": {
  "Type" : "Task",
  "Resource": "arn:aws:lambda:******:function:Zero",
  "Next": "NextState"
},
"DefaultState": {
  "Type" : "Task",
  "Resource": "arn:aws:lambda:******:function:NotZero",
  "Next": "NextState"
}

Let assume that input to this state is:

{
   "value": 0,
   "output1": object1,
   "output2": object2,
}

My issue is that I have to pass output1 to ValueIsZero state and output2 to DefaultState. I know that it is possible to change InputPath in ValueIsZero and DefaultState states. But this way isn't acceptable for me because I am calling these states from some other states also.

I tried to modify ChoiceStateX state like next:

"ChoiceStateX": {
  "Type": "Choice",
  "Choices": [
    {
      "Variable": "$.value",
      "NumericEquals": 0,
      "OutputPath": "$.output1",
      "Next": "ValueIsZero"
    }
  ],
  "Default": "DefaultState"
}

I got next error in this case: Field OutputPath is not supported.

How is it possible to implement this functionality?

PS: In the current moment I am using 'proxy' states between ChoiceStateX and ValueIsZero/DefaultState where modifying the output.

I have checked:

but haven't found a solution yet.


Solution

  • It looks like it isn't possible to specify different OutputPath for one state.

    The solution with proxy states doesn't look graceful.

    I have solved this issue in another way in the state before ChoiceStateX. I am setting instances of different types in output property and only route it on ChoiceStateX state.

    My input of ChoiceStateX state looks like:

    {
       "value": value,
       "output": value==0 ? object1 : object2
    }
    

    End final version of ChoiceStateX state:

    "ChoiceStateX": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.value",
          "NumericEquals": 0,
          "Next": "ValueIsZero"
        }
      ],
      "OutputPath": "$.output",
      "Default": "DefaultState"
    }
    

    It is still isn't perfect, because I implement the same logic in two places.