首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >捕获后的AWS步骤函数失败

捕获后的AWS步骤函数失败
EN

Stack Overflow用户
提问于 2021-09-21 18:47:36
回答 1查看 601关注 0票数 1

我的AWS步骤功能有三个阶段:

  1. 阶段1-Lambda
  2. 阶段2- AWS批处理
  3. 阶段3- AWS批处理(强制清理)

一切都很好,如果第1阶段失败了,那么它就会移动到清理阶段。但是,由于清理阶段总是经过,步骤函数的最终结果总是Pass,而如果阶段1或2失败,我需要执行清理,但是步骤函数的最终结果应该是失败。

调查的备选方案:

解决这一问题的一种方法是在缓存中维护一个标志是否有错误,但我想知道是否有内置的this.

  • Another选项是使用结果路径来检查错误,但我不知道如何从AWS批处理访问这个结果.

谢谢你对此的任何建议。

我在第一阶段和第二阶段中添加了以下Catch块:

代码语言:javascript
复制
"Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "Cleanup"
        }
]

清理阶段如下:

代码语言:javascript
复制
"Cleanup": {
  "Type": "Task",
  "Resource": "arn:aws:states:::batch:submitJob.sync",
  "Parameters": {
    "JobDefinition": "arn:aws:batch:<region>:<account>:job-definition/MyCleanupJob",
    "JobName": "cleanup",
    "JobQueue": "arn:aws:batch:<region>:<account>:job-queue/MyCleanupQueue",
    "ContainerOverrides": {
      "Command": [
        "java",
        "-jar",
        "cleanup.jar" ############ need to specify if an error occured as a command line parameter ###########
      ],
    }
  },
  "End": true
}
EN

回答 1

Stack Overflow用户

发布于 2021-09-21 23:57:44

在下面的机制中,@LRutten用于引导这条路径。

对于所有成功阶段,将响应附加到overwritten.

  • Set,否则前面的结果将是错误到异常的响应路径,
  1. 使用一种选择来根据错误元素

的存在来决定step函数是否失败

以下是最终输出:

代码语言:javascript
复制
"MyLambda": {
  "Type": "Task",
  "Resource": "arn:aws:lambda:<region>:<account>:function:MyLambda",
  "ResultPath": "$.mylambda",   #### All results from the lambda are added to "mylambda" in the JSON
  "Catch": [
    {
      "ErrorEquals": [
        "States.ALL"
      ],
      "ResultPath": "$.error",  #### If an error occurs it is appended to the result path as an "error" element
      "Next": "Cleanup"
    }
  ],
  "Next": "MyBatch"
},

"MyBatch": {
  "Type": "Task",
  "Resource": "arn:aws:states:::batch:submitJob.sync",
  "Parameters": {
    "JobDefinition": "arn:aws:batch:<region>:<account>:job-definition/MyBatchJob",
    "JobName": "cleanup",
    "JobQueue": "arn:aws:batch:<region>:<account>:job-queue/MyBatchQueue",
    "ContainerOverrides": {
      "Command": [
        "java",
        "-jar",
        "mybatch.jar"
      ],
    }
  },
  "ResultPath": "$.mybatch",
  "Catch": [
    {
      "ErrorEquals": [
        "States.ALL"
      ],
      "ResultPath": "$.error",
      "Next": "Cleanup"
    }
  ],
  "Next": "Cleanup"
},
"Cleanup": {
  "Type": "Task",
  "ResultPath": "$.cleanup",
  "Resource": "arn:aws:states:::batch:submitJob.sync",
  "Parameters": {
    "JobDefinition": "arn:aws:batch:<region>:<account>:job-definition/MyCleanupJob",
    "JobName": "cleanup",
    "JobQueue": "arn:aws:batch:<region>:<account>:job-queue/MyCleanupQueue",
    "ContainerOverrides": {
      "Command": [
        "java",
        "-jar",
        "cleanup.jar"
      ],
    }
  },
  "Next": "Should Fail"
},
"Should Fail" :{
  "Type" : "Choice",
  "Choices" : [
    {
      "Variable" : "$.error",   #### If an error element is present it means it is a Failure
      "IsPresent": true,
      "Next" : "Fail"
    }
  ],
  "Default" : "Pass"
},
"Fail" : {
  "Type" : "Fail",
  "Cause": "Step function failed"
},
"Pass" : {
  "Type" : "Pass",
  "Result": "Step function passed",
  "End" : true
}
 
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69274108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档