状态机忽略步进功能错误

问题描述 投票:0回答:1

我的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-lambdaamazon/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请求:目标服务器无法响应“}}

然后执行失败。我希望步函数错误也有类似的行为。

处理步进功能故障的正确方法是什么?

amazon-web-services state-machine aws-step-functions
1个回答
0
投票

您的步进功能正常,我复制了它并用我的python lambda运行它,输出错误:enter image description here“ NameError:名称'y'未定义”。

这里是步进功能的结果:enter image description here

问题出在您容器的输出中,没有说“ errorType”,状态机需要它来显示错误。

让我知道是否有帮助

© www.soinside.com 2019 - 2024. All rights reserved.