Step Function error handling

0

I have a state that updates DynamoDB by shifting the first word off a list of words. It returns UPDATED_OLD so that the word can be grabbed in the ResultSelector block as index 0 and passed on to the next step. If there are words in the list this works fine, but if the list is empty, there is nothing at index 0 and Step Functions throws a States.Runtime error and the execution fails. I added a Catch block but it isn't catching as expected. Can this error be caught? Thank you.

gefragt vor 2 Jahren633 Aufrufe
1 Antwort
0

Use a Choice state to check for existence of array[0]. Something like this:

{
  "StartAt": "CheckArrayEmpty",
  "States": {
    "CheckArrayEmpty": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.array[0]",
          "IsPresent": true,
          "Next": "NotEmpty"
        }
      ],
      "Default": "Empty"
    },
    "NotEmpty": {
      "Type": "Pass",
      "End": true
    },
    "Empty": {
      "Type": "Pass",
      "End": true
    }
  }
}
profile pictureAWS
EXPERTE
Uri
beantwortet vor 2 Jahren
  • Thank you for replying Uri. I came up with a work-around outside of this step function but I would still like to know about catching the error. Is this a bug in the service?

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen