Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 395
Lee Oades Avatar asked Jan 03 '23 17:01

Lee Oades


1 Answers

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": "..."
  }
}
like image 79
jjanzic Avatar answered Jan 13 '23 09:01

jjanzic