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.

asked 2 years ago624 views
1 Answer
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
EXPERT
Uri
answered 2 years ago
  • 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?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions