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.

已提問 2 年前檢視次數 633 次
1 個回答
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
專家
Uri
已回答 2 年前
  • 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?

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南