简体   繁体   English

AWS Step Functions:在Lambda异常上,获取原始输入?

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

The Setup 安装程序

I have an AWS state machine. 我有一台AWS状态机。 I have a Lambda that may return a result, or may throw an exception. 我有一个可能返回结果的Lambda,或者可能抛出异常。 The step has a catch block defined and depending on the type of exception, follows a different execution path. 该步骤定义了一个catch块,并根据异常的类型,遵循不同的执行路径。

The Problem 问题

However, I want to store the input of the Lambda that failed so that it can be reapplied at a later date. 但是,我想存储失败的Lambda 输入 ,以便以后可以重新应用它。

The output from the failed Lambda is the exception. 失败的Lambda的输出是例外。

What I've Tried 我试过的

Adding OutputPath and ResultPath do not apply when it's an exception. 添加OutputPath和ResultPath时,如果它是异常,则不适用。

I don't really want to have to always throw custom exceptions and attach the json input, and then parse through exception messages. 我真的不想总是抛出自定义异常并附加json输入,然后解析异常消息。

I've tried using a Parallel, sending the input to my Lambda and to a Pass. 我尝试过使用Parallel,将输入发送到我的Lambda和Pass。 The result is then an array with the Lambda output (either a successful output, or the exception) and the original input. 结果是一个带有Lambda输出(成功输出或异常)和原始输入的数组。 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. 但是,现在我需要添加一个Choice来检查是否有异常,然后继续成功输出,或者用原始输入分支。 I can't seem to define a JsonPath in the Choice to check for whether "Error" exists in the first element of the array. 我似乎无法在Choice中定义JsonPath来检查数组的第一个元素中是否存在“Error”。

You can do this using ResultPath in Catch clause which will put the exception output into a specific path under the original input. 您可以使用Catch子句中的ResultPath执行此操作,该子句将异常输出放在原始输入下的特定路径中。

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": "..."
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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