简体   繁体   English

aws step 函数流中的最后一个状态是否可以包含 catch 语句?

[英]can the last state in a aws step function flow contain a catch statement?

I have a step functions orchestration flow and I want to do error handling in some of the states using the catch field.我有一个步骤函数编排流程,我想使用 catch 字段在某些状态下进行错误处理。 However, the catch field requires a Next assignment and therefore I am unable to include a catch field in my last state if i want my step function to run.但是,catch 字段需要 Next 赋值,因此如果我希望我的 step 函数运行,我无法在我的最后一个状态中包含 catch 字段。

I would like to have a catch field in the last state of the flow but I am wondering if it is good practise to have a catch statement in the last state.我想在流的最后一个状态有一个 catch 字段,但我想知道在最后一个状态有一个 catch 语句是否是一个好习惯。 When i introduce an ending state eg a Type:Succeed state the stepfunction is able to run.当我引入结束状态时,例如 Type:Succeed 状态,stepfunction 可以运行。 But this solution feels a bit hacky.但是这个解决方案感觉有点hacky。

I have tried to set the value of Next in the catch field to End.我试图将 catch 字段中 Next 的值设置为 End。 But was thrown this error in cloudformation when it tried to update the stack.但是在尝试更新堆栈时在 cloudformation 中抛出了这个错误。

Resource handler returned message: "Invalid State Machine Definition: 'MISSING_TRANSITION_TARGET: Missing 'Next' target: EndState at /States/last_jobs/Branches[0]/States/last_state/Catch[0]/Next' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Proxy: null)" (HandlerErrorCode: InvalidRequest)资源处理程序返回消息:“无效状态机定义:'MISSING_TRANSITION_TARGET:缺少'下一个'目标:EndState at /States/last_jobs/Branches[0]/States/last_state/Catch[0]/Next'(服务:AWSStepFunctions;状态代码:400;错误代码:InvalidDefinition;代理:null)”(HandlerErrorCode:InvalidRequest)

The purpose of Catch is so you can tell Step Functions to take a different action in response to a failure (after retries) as the default behavior will be to fail the execution. Catch 的目的是让您可以告诉 Step Functions 采取不同的操作来响应失败(重试后),因为默认行为将使执行失败。 That action needs to be captured in the workflow, hence the need for this to point to another state where that action is described.该操作需要在工作流中捕获,因此需要 this 指向描述该操作的另一个状态。

I'm not 100% sure what you are looking to accomplish with this catch block, but I suspect it's one of the following cases.我不是 100% 确定你希望用这个 catch 块完成什么,但我怀疑它是以下情况之一。

If you are looking to take further action to compensate, then you will need to add that to your workflow (eg another task or a wait state that re-enters into the existing flow).如果您希望采取进一步的行动来补偿,那么您需要将其添加到您的工作流程中(例如,另一个任务或重新进入现有流程的等待状态)。

If you are looking to provide a specific failure cause and / or error as opposed to the default you would get from the task failing, then you will need a Fail state with those specifics.如果您希望提供特定的失败原因和/或错误,而不是您从任务失败中获得的默认值,那么您将需要具有这些细节的失败状态。 And set that as Next for your Catch.并将其设置为您的 Catch 的下一步。

If you are looking to ignore this task failure and complete the workflow successfully, then you need a Succeed state that you can specify as Next for your Catch.如果您希望忽略此任务失败并成功完成工作流,那么您需要一个成功状态,您可以为您的 Catch 指定为下一步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM