amazon-web-services - 状态机忽略阶跃函数错误

标签 amazon-web-services state-machine aws-step-functions

我的 aws 步骤函数工作流程有问题。我定义了多个状态,我想为它们添加错误处理。问题是,对于来自函数的任何错误(引发的异常、未处理的 promise 拒绝或代码错误),状态机总是获得 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 docker 镜像在本地环境中对其进行测试。 State1Function 执行的 sam 输出:

2019-11-19T08:37:40.910Z b2421c61-d31c-1482-6a65-f6cbd42328a7 ERROR Invoke Error {"errorType":"ReferenceError","errorMessage":"not is not defined","stack":["ReferenceError: not is not defined"," at Runtime.module.exports [as handler] (/var/task/path/to/state1function.js:7:5)"," at 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,"LambdaFunctionSucceededEventDetails":{"Output":"{\"errorType\":\"ReferenceError\",\"errorMessage\":\"not is not defined\"}"}}

执行继续。

当我停止 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":{"Error":"Lambda.SdkClientException","Cause":"Unable to execute HTTP request: The target server failed to respond"}}

然后执行失败。我希望在阶跃函数错误上有类似的行为。

处理步骤函数失败的正确方法是什么?

最佳答案

你的step函数没问题, 我复制它并用我的 python lambda 运行它输出错误: enter image description here “NameError:名称‘y’未定义”。

这是阶跃函数的结果: enter image description here

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

如果有帮助请告诉我

关于amazon-web-services - 状态机忽略阶跃函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58929953/

相关文章:

aws-lambda - AWS 步骤函数 - 嵌套映射类型

amazon-web-services - 具有自动缩放功能的AWS RDS

javascript - 适用于 Javascript 的 AWS uploadpart 函数中的 XMLHttpRequest 出现网络故障

amazon-web-services - AWS 步骤函数 : List Definition Substitutions

c++ - 如何在 boost::statechart state_machine 对象中获取当前最派生的状态?

node.js - Step Functions 错误处理函数参数

amazon-web-services - 如何使用 API 网关调用 AWS 步骤函数?

amazon-web-services - "Message": "Your request: '/_cluster/allocation/reroute ' is not allowed."}

javascript - 如何实现对文本中自己的html标签的解析

c++ - Boost Statechart vs. 元状态机