【问题标题】:State machine ignores step function errors状态机忽略阶跃函数错误
【发布时间】:2020-03-14 17:32:48
【问题描述】:

我的 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 docker 镜像在本地环境中对其进行测试。用于 State1Function 执行的sam 的输出:

2019-11-19T08:37:40.910Z b2421c61-d31c-1482-6a65-f6cbd42328a7 错误调用错误 {"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 未定义\"}"}}

执行继续。

当我停止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":"无法执行 HTTP 请求:目标服务器响应失败"}}

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

处理阶跃函数故障的正确方法是什么?

【问题讨论】:

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


    【解决方案1】:

    你的step函数没问题, 我复制了它并用我的 python lambda 运行它,输出错误: "NameError: name 'y' is not defined"。

    这是 step 函数的结果:

    问题出在容器的输出中,它没有说“errorType”,并且状态机需要它来查看错误。

    如果有帮助请告诉我

    【讨论】:

      猜你喜欢
      • 2021-10-08
      • 1970-01-01
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多