我的aws步骤功能工作流程有问题。我定义了多个状态,我想向它们添加错误处理。问题是,对于来自函数的任何错误(引发异常,未处理的承诺拒绝或代码错误),状态机始终会获取LambdaFunctionSucceeded并继续执行直到最后一个状态完成。
这里是状态机定义的示例,由于本示例过于复杂,因此我不提供自己的定义
{
"Comment": "Example state machine",
"StartAt": "State1",
"States": {
"State1": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-2:123456789012:function:State1Function",
"Next": "Finish",
"ResultPath": "$.State1Result",
"Catch": [
{
"ErrorEquals": [
"States.TaskFailed"
],
"Next": "Failure"
}
]
},
"Failure": {
"Type": "Fail",
"Error": "$"
},
"Finish": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-2:123456789012:function:FinishFunction",
"End": true,
"Catch": [
{
"ErrorEquals": [
"States.TaskFailed"
],
"Next": "Failure"
}
]
}
}
}
State1Function示例:
module.exports = async event => {
not().defined; // but execution does not fail
// do stuff
};
我使用sam local start-lambda
和amazon/aws-stepfunctions-local
码头工人镜像在本地环境中对其进行测试。用于执行State1Function的sam
的输出:
2019-11-19T08:37:40.910Z b2421c61-d31c-1482-6a65-f6cbd42328a7错误调用错误{“ errorType”:“ ReferenceError”,“ errorMessage”:“未定义”,“堆栈”:[“ ReferenceError:未定义“,”在Runtime.module.exports [作为处理程序](/var/task/path/to/state1function.js:7:5)“,”在Runtime.handleOnce(/ var / runtime / Runtime.js:66:25)“]}
amazon/aws-stepfunctions-local
容器的输出(处理状态机的执行):
2019-11-19 08:37:41.348:arn:aws:states:eu-west-2:123456789012:execution:test:test4:{“ Type”:“ LambdaFunctionSucceeded”,“ PreviousEventId”:4,“ LambdaFunctionSucceedededEventDetails “:{”输出“:” {\“ errorType \”:\“ ReferenceError \”,\“ errorMessage \”:\“未定义\”}“}}]
继续执行。
当我停止sam local start-lambda
并且状态机无法调用步骤函数之一时,输出为:
2019-11-19 08:37:53.406:arn:aws:states:eu-west-2:123456789012:execution:test:test4:{“ Type”:“ LambdaFunctionFailed”,“ PreviousEventId”:23,“ LambdaFunctionFailedEventDetails “:{”错误“:” Lambda.SdkClientException“,”原因“:”无法执行HTTP请求:目标服务器无法响应“}}
然后执行失败。我希望步函数错误也有类似的行为。
处理步进功能故障的正确方法是什么?