How to Stop Running Executions in AWS Step Functions (Console, CLI, & Boto3)

If you have an AWS Step Functions state machine caught in an infinite loop, or if a bug in your pipeline triggered thousands of unintended runs, you need to halt them immediately to prevent ballooning AWS costs.

While AWS allows you to stop individual executions easily, stopping hundreds or thousands of them requires a more programmatic approach. In this guide, we will walk you through the three best ways to stop running executions in AWS Step Functions: via the AWS Management Console, the AWS CLI, and a Python Boto3 script for bulk operations.


Contents

Stop a Single Execution via AWS Console (Best for Few Runs)

If you only have a handful of rogue executions, the AWS Management Console is the fastest way to manually terminate them.

Step-by-step guide:

  1. Log in to the AWS Management Console and navigate to Step Functions.
  2. Click on the name of your specific State machine.
  3. Scroll down to the Executions tab.
  4. Click the Status dropdown menu and filter the list by Running.
  5. Click the hyperlinked Execution Name of the run you want to halt.
  6. In the top right corner of the execution details page, click the Stop execution button.

Note: You can provide an optional “Error” and “Cause” message before confirming, which is highly recommended for audit trails.

Bulk Stop Running Executions using Boto3 (Best for High Volume)

Step Functions does not have a native “Stop All” button. If an EventBridge rule or S3 trigger accidentally invoked your state machine thousands of times, you must paginate through the running executions and stop them programmatically.

Here is a production-ready Python Boto3 script that isolates only the RUNNING executions and cleanly shuts them down:

Python

import boto3

def stop_all_running_executions(state_machine_arn):
    """
    Paginates through all active executions of a given AWS Step Functions 
    State Machine and stops them to prevent further billing/processing.
    """
    sfn_client = boto3.client('stepfunctions')
    paginator = sfn_client.get_paginator('list_executions')
    
    # Filter strictly for RUNNING executions to avoid altering failed/succeeded runs
    page_iterator = paginator.paginate(
        stateMachineArn=state_machine_arn,
        statusFilter='RUNNING'
    )
    
    stopped_count = 0
    
    for page in page_iterator:
        for execution in page['executions']:
            exec_arn = execution['executionArn']
            
            # Issue the StopExecution API call
            sfn_client.stop_execution(
                executionArn=exec_arn,
                error='ManualBulkStop',
                cause='Stopped programmatically via Boto3 cleanup script'
            )
            print(f"Successfully stopped execution: {exec_arn}")
            stopped_count += 1
            
    print(f"Cleanup complete. Total running executions stopped: {stopped_count}")

if __name__ == '__main__':
    # Replace with your actual State Machine ARN
    TARGET_ARN = 'arn:aws:states:us-east-1:123456789012:stateMachine:MyStateMachine'
    stop_all_running_executions(TARGET_ARN)

Stop an Execution via AWS CLI (Best for CI/CD)

If you already have the specific Execution ARN—perhaps pulled from a CloudWatch alarm or a failure log—you can terminate it instantly from your terminal using the AWS CLI.

Run the following stop-execution command:

Bash

aws stepfunctions stop-execution \
    --execution-arn "arn:aws:states:us-east-1:123456789012:execution:MyStateMachine:12345abcde" \
    --error "ManuallyStopped" \
    --cause "Halted via AWS CLI due to pipeline error"

Frequently Asked Questions (FAQ)

Does stopping an execution stop in-flight AWS Lambda functions?

No. When you call the StopExecution API, Step Functions immediately halts its tracking and transitions the execution to an aborted state. However, if a task (like an AWS Lambda function, AWS Batch job, or ECS task) was already invoked and is actively running, that underlying resource will continue to run until it completes or times out. Its final output or failure will simply be ignored by Step Functions.

Will I be billed for stopped executions?

AWS Step Functions charges based on state transitions. Once an execution is explicitly stopped, no further state transitions will occur for that specific run, meaning billing for that execution halts immediately.

Can I delete the State Machine while executions are running?

Yes. If a state machine is completely beyond recovery and you want to wipe it out, you can delete the entire state machine. AWS will immediately abort all active executions and transition the resource to a DELETING status. Ensure you have disabled any upstream triggers (like Amazon EventBridge) first, or they will begin generating delivery errors.

Scroll to Top