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.

preguntada hace 2 años633 visualizaciones
1 Respuesta
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
EXPERTO
Uri
respondido hace 2 años
  • 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?

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas