Reputation: 69
Is there a way to cancel a state machine execution without fully exiting the step functions? Our state machine has a failure path that does a lot of cleanup which would be missed if the execution is canceled mid workflow.
I am stumped and not sure if anyone else has ever come across a solution to this?
/MN
Upvotes: 0
Views: 1496
Reputation: 2800
I know this is an old question, but I have run into a similar use case. I wish I could just do it all in my state machine, but so far I have not found that capability. What I implemented instead was to have a Lambda function that is triggered by an EventBridge rule. I use an EventBridge rule with:
EventPattern:
source:
- aws.states
detail-type:
- Step Functions Execution Status Change
detail:
status:
- SUCCEEDED
- FAILED
- ABORTED
- TIMED_OUT
Then in my Lambda function I can inspect the event and the execution history to perform my cleanup.
Upvotes: 5
Reputation: 2400
Wrap the entire state machine in a parallel state task but only have the one branch - your main path. You can then attach a catch for "States.All" and point that to your cleanup lambda tasks.
But if you mean cancel as in actively use the CLI or an SDK to cancel a state machine execution with stop execution
Then there isn't a way to do so inside the states machine. However. If you use the SDK to send the call from inside a lambda you could call your clean up functionality after that (even call the same lambdas/services your step function uses) and get most of what you probably need out of describe execution
CLI/SDK command
Upvotes: 0