Nmanny
Nmanny

Reputation: 111

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. 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.

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. When i introduce an ending state e.g. a Type:Succeed state the stepfunction is able to run. But this solution feels a bit hacky.

I have tried to set the value of Next in the catch field to End. But was thrown this error in cloudformation when it tried to update the stack.

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)

Upvotes: 0

Views: 1399

Answers (1)

Justin Callison
Justin Callison

Reputation: 2199

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. That action needs to be captured in the workflow, hence the need for this to point to another state where that action is described.

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.

If you are looking to take further action to compensate, then you will need to add that to your workflow (e.g. 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.

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.

Upvotes: 0

Related Questions