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.

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?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠