Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Input and Output Processing
  • Choice

but haven't found a solution yet.

like image 377
RredCat Avatar asked Jan 26 '26 11:01

RredCat


1 Answers

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.

like image 142
RredCat Avatar answered Jan 28 '26 02:01

RredCat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!