Ganesh Satpute
Ganesh Satpute

Reputation: 3941

AWS step function: Use nested variable inside condition

I am are trying to write a step function where each function.

Let's say this is the output of one of the function is

{ 
    ...
    "foo": {
      "1": "one"
      "2": "two", 
      "5": "five"
     },
    "current": 2
    ...
}

I have a choice statement, which needs to check what is the value of test_key and dereference it in foo dictionary.

...
"ChoiceState": {
      "Type" : "Choice",
      "Choices": [
        {
          "Variable": "$.foo['$.current']",  <--- This is unsupported
          "StringEquals": "two",
          "Next": "TwoFunction"
        }, 
        {
          "Variable": "$.foo['$.current']",  <--- This is unsupported
          "StringEquals": "three",
          "Next": "ThreeFunction"
        }
        ...
      ],
      "Default": "DefaultFunction"
    }
...

How do I use dynamic reference in choice states?

Upvotes: 1

Views: 1319

Answers (1)

adamwong
adamwong

Reputation: 1194

JSONPath doesn't support dynamic keys so this isn't possible. You have to restructure your input data or combine multiple Choice Rules with the And comparison operator to check the corresponding property based on current:

{
  "And": [
    {
      "Variable": "$.current",
      "StringEquals": "2"
    },
    {
      "Variable": "$.foo.2",
      "StringEquals": "two"
    }
  ],
  "Next": "TwoFunction"
}

Upvotes: 1

Related Questions