Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I delete an AWS Step Functions state machine stuck in a "deleting" loop

I'm trying to delete an obsolete step function that's no longer needed, However it's been stuck in the "deleting" stage for a few weeks now. However from the console it says there are 0 Running executions. How to I delete the state machine if there are no currently running executions?

like image 687
Aaron_H Avatar asked Dec 19 '22 03:12

Aaron_H


1 Answers

The AWS Step Functions console, at the time of this writing, only pulls the last 1000 most recent executions. So when it says 0 running executions, it's just describing out of the last 1000 executions.

In order to see all the currently running executions, you'll need to use the AWS CLI. You can do this by running (in a unix shell):

export STATE_MACHINE_ARN=#Enter the state machine arn, arn:aws:states:...    
aws stepfunctions list-executions --state-machine-arn $STATE_MACHINE_ARN --status-filter RUNNING --output text

To automate deleting each of these running executions, run:

aws stepfunctions list-executions --state-machine-arn $STATE_MACHINE_ARN --status-filter RUNNING --output text | awk '{print $2}' | xargs -n 1 aws stepfunctions stop-execution --error "Manual Abort" --execution-arn

You will see the stop time of each of the executions being returned. When that completes, you can finish deleting it again using

aws stepfunctions delete-state-machine --state-machine-arn $STATE_MACHINE_ARN
like image 102
Aaron_H Avatar answered Jan 22 '23 08:01

Aaron_H