How to use Boto3 to stop a workflow in AWS Glue Data Catalog

AWS Glue workflows can be programmatically controlled using the Boto3 library. This article demonstrates how to stop a running workflow in AWS Glue Data Catalog using Python.

Prerequisites

Before stopping a workflow, ensure you have ?

  • AWS credentials configured (via AWS CLI or environment variables)

  • Boto3 library installed: pip install boto3

  • Appropriate IAM permissions for AWS Glue operations

  • A running workflow with a valid workflow_name and run_id

Method: Using stop_workflow_run()

The stop_workflow_run() method requires two mandatory parameters ?

  • Name − The workflow name to stop

  • RunId − The unique identifier of the workflow run

Example

import boto3
from botocore.exceptions import ClientError

def stop_a_workflow(workflow_name, run_id):
    session = boto3.session.Session()
    glue_client = session.client('glue')
    
    try:
        response = glue_client.stop_workflow_run(
            Name=workflow_name, 
            RunId=run_id
        )
        return response
    except ClientError as e:
        raise Exception("boto3 client error in stop_a_workflow: " + str(e))
    except Exception as e:
        raise Exception("Unexpected error in stop_a_workflow: " + str(e))

# Example usage (requires actual workflow name and run ID)
# result = stop_a_workflow("test-daily", "wr_64e880240692fddd5e1b19aed587f856bc20a96f54bc")
# print(result)

Response Format

When successful, the function returns a response containing ?

{
    'RunId': 'wr_64e880240692fddd5e1b19aed587f856bc20a96f54bc',
    'ResponseMetadata': {
        'RequestId': '782e953b-8ee3-4876-9b2c-cd35e147b513',
        'HTTPStatusCode': 200,
        'HTTPHeaders': {
            'date': 'Sun, 28 Mar 2021 08:11:02 GMT',
            'content-type': 'application/x-amz-json-1.1',
            'content-length': '79',
            'connection': 'keep-alive'
        },
        'RetryAttempts': 0
    }
}

Error Handling

Common exceptions include ?

  • ClientError − AWS service−related errors (invalid workflow name, insufficient permissions)

  • Exception − General Python exceptions (network issues, authentication problems)

Key Points

  • The workflow must be in a running state to be stopped

  • Stopping a workflow will halt all active jobs within that workflow

  • The RunId is unique for each workflow execution

  • Ensure proper IAM permissions: glue:StopWorkflowRun

Conclusion

Use stop_workflow_run() to programmatically halt AWS Glue workflows. Always include proper error handling and ensure you have valid workflow names and run IDs before attempting to stop a workflow.

Updated on: 2026-03-25T18:47:59+05:30

598 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements