How can I use Choice to test for if an input array contains a given filter?

Viewed 511

Given a Map state thats output is an array similar to the following:

[
  {
    "ProcessState": {
      "Status": "SUCCESS"
    }
  },
  {
    "ProcessState": {
      "Status": "SUCCESS"
    }
  },
  {
    "ProcessState": {
      "Status": "FAILURE"
    }
  }
]

I would like to be able to test if there is an element with Status = 'FAILURE'. I attempted to use a Choice with a choice as follows:

{
  "Variable": "$..ProcessState[?(Status == FAILURE)]",
  "IsPresent": true,
  "Next": "Items Contained Failure"
}

When attempting this I get Value is not a Reference Path: Illegal '..' ...

I'm thinking to attempt to use a Pass as an intermediate step, but I think that's just going to fail that it can't find anything if no entries match.

1 Answers

This has been solved by having the Map state ResultSelector to perform the filtering.

"ResultSelector": {
  "QueueFailures.$": "$[?(@.ProcessState.Status == 'FAILED')]"
},
"ResultPath": "$.ProcessResult"

The Choice state can now just test for the presence of the first failure item.

"Test Queue Failures": {
  "Type": "Choice",
  "Default": "Mark Decision Run Ready",
  "Choices": [
    {
      "Variable": "$.ProcessResult.QueueFailures[0]",
      "IsPresent": true,
      "Next": "Queue Contains Failures"
    }
  ]
}
Related