简体   繁体   中英

AWS Step Functions: On Lambda exception, get original input?

The Setup

I have an AWS state machine. I have a Lambda that may return a result, or may throw an exception. The step has a catch block defined and depending on the type of exception, follows a different execution path.

The Problem

However, I want to store the input of the Lambda that failed so that it can be reapplied at a later date.

The output from the failed Lambda is the exception.

What I've Tried

Adding OutputPath and ResultPath do not apply when it's an exception.

I don't really want to have to always throw custom exceptions and attach the json input, and then parse through exception messages.

I've tried using a Parallel, sending the input to my Lambda and to a Pass. The result is then an array with the Lambda output (either a successful output, or the exception) and the original input. However, now I need to add a Choice to check to see if there was an exception, and then either continue with the successful output, or branch off with the original input. I can't seem to define a JsonPath in the Choice to check for whether "Error" exists in the first element of the array.

You can do this using ResultPath in Catch clause which will put the exception output into a specific path under the original input.

Eg:

"Catch": [{ 
  "ErrorEquals": ["States.ALL"], 
  "Next": "NextTask", 
  "ResultPath": "$.error" 
}]

with input

{"foo": "bar"}

in case of exception will produce output like:

{
  "foo": "bar",
  "error": {
    "Error": "..."
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM