AWS Step 函数句柄 Lambda.Unknown
AWS Step Function Handle Lambda.Unknown
我有一个简单的 AWS 状态机,有两个执行 C# lambda 函数的任务状态,和一个处理状态错误处理程序来处理 "States.ALL":
{
"Comment": "StateMachine1",
"StartAt": "step1",
"States": {
"step1": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-2:0000:function:step1",
"Catch": [ {
"ErrorEquals": ["States.ALL"],
"Next": "CatchAllFallback"
} ],
"Next": "step2"
},
"step2": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-2:0000:function:step2",
"Catch": [ {
"ErrorEquals": ["States.ALL"],
"Next": "CatchAllFallback"
} ],
"End": true
},
"CatchAllFallback": {
"Type": "Pass",
"Result": "This is a fallback from any error code",
"End": true
}
}
}
当其中一个步骤失败时,我得到以下内容作为我 "CatchAllFallback" 的输入:
"Error": "Lambda.Unknown",
"Cause": "The cause could not be determined because Lambda did not return an error type."
当我查看 Cloudwatch 日志时,我发现步骤超时。我的问题是:如何在我的错误处理程序中获取该信息而不仅仅是 "Lambda.Unknown"?我知道这一定是可能的,但是在花了几个小时在网上搜索之后,我不知道该怎么做。如有任何建议,我们将不胜感激。
我不认为这是默认支持的(但也许有人可以证明我错了?)。这是因为问题的根源。 AWS Step Functions 期望有效的错误类型将其传递到下一个状态,但您的 Lambda 超时,因此无法传递有效的错误类型。
但是!您可以在 Lambda(s) 中构建一个解决方法。
只需检查 Context Object
中的 RemainingTime ,一旦它接近超时,您就会抛出一个异常,然后可以将其映射到有效的错误类型。
Information about the remaining time of function execution can be used
to specify function behavior when nearing the timeout
您的 lambda 需要抛出相关错误,以便 step 函数提供更好的输出,documentation 使用 c#
对此场景进行了解释
例子
namespace Example {
public class AccountAlreadyExistsException : Exception {
public AccountAlreadyExistsException(String message) :
base(message) {
}
}
}
namespace Example {
public class Handler {
public static void CreateAccount() {
throw new AccountAlreadyExistsException("Account is in use!");
}
}
}
我有一个简单的 AWS 状态机,有两个执行 C# lambda 函数的任务状态,和一个处理状态错误处理程序来处理 "States.ALL":
{
"Comment": "StateMachine1",
"StartAt": "step1",
"States": {
"step1": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-2:0000:function:step1",
"Catch": [ {
"ErrorEquals": ["States.ALL"],
"Next": "CatchAllFallback"
} ],
"Next": "step2"
},
"step2": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-2:0000:function:step2",
"Catch": [ {
"ErrorEquals": ["States.ALL"],
"Next": "CatchAllFallback"
} ],
"End": true
},
"CatchAllFallback": {
"Type": "Pass",
"Result": "This is a fallback from any error code",
"End": true
}
}
}
当其中一个步骤失败时,我得到以下内容作为我 "CatchAllFallback" 的输入:
"Error": "Lambda.Unknown",
"Cause": "The cause could not be determined because Lambda did not return an error type."
当我查看 Cloudwatch 日志时,我发现步骤超时。我的问题是:如何在我的错误处理程序中获取该信息而不仅仅是 "Lambda.Unknown"?我知道这一定是可能的,但是在花了几个小时在网上搜索之后,我不知道该怎么做。如有任何建议,我们将不胜感激。
我不认为这是默认支持的(但也许有人可以证明我错了?)。这是因为问题的根源。 AWS Step Functions 期望有效的错误类型将其传递到下一个状态,但您的 Lambda 超时,因此无法传递有效的错误类型。
但是!您可以在 Lambda(s) 中构建一个解决方法。
只需检查 Context Object
中的 RemainingTime ,一旦它接近超时,您就会抛出一个异常,然后可以将其映射到有效的错误类型。
Information about the remaining time of function execution can be used to specify function behavior when nearing the timeout
您的 lambda 需要抛出相关错误,以便 step 函数提供更好的输出,documentation 使用 c#
对此场景进行了解释例子
namespace Example {
public class AccountAlreadyExistsException : Exception {
public AccountAlreadyExistsException(String message) :
base(message) {
}
}
}
namespace Example {
public class Handler {
public static void CreateAccount() {
throw new AccountAlreadyExistsException("Account is in use!");
}
}
}