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

In this article, we will see how to stop a trigger in AWS Glue Data Catalog using the boto3 library in Python. AWS Glue triggers are used to start ETL jobs based on schedules or events, and sometimes you need to stop them programmatically.

Prerequisites

Before running the code, ensure you have:

  • AWS credentials configured (via AWS CLI, environment variables, or IAM roles)

  • boto3 library installed: pip install boto3

  • Appropriate IAM permissions for Glue operations

Approach to Stop a Glue Trigger

  • Step 1: Import boto3 and botocore exceptions to handle errors

  • Step 2: Create an AWS session using boto3 library

  • Step 3: Create an AWS client for glue service

  • Step 4: Use the stop_trigger() method with the trigger name

  • Step 5: Handle exceptions for better error management

Example Code

The following code demonstrates how to stop a trigger in AWS Glue Data Catalog ?

import boto3
from botocore.exceptions import ClientError

def stop_a_trigger(trigger_name):
    session = boto3.session.Session()
    glue_client = session.client('glue')
    
    try:
        response = glue_client.stop_trigger(Name=trigger_name)
        return response
    except ClientError as e:
        raise Exception("boto3 client error in stop_a_trigger: " + e.__str__())
    except Exception as e:
        raise Exception("Unexpected error in stop_a_trigger: " + e.__str__())

# Example usage
result = stop_a_trigger("test-daily")
print(result)

Output

The output shows the response metadata confirming the trigger has been stopped ?

{'Name': 'test-daily', 'ResponseMetadata': {'RequestId': 'b2109689-*******************-d', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 28 Mar 2021 08:00:04 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '26', 'connection': 'keep-alive', 'x-amzn-requestid': 'b2109689-***********************-d'}, 'RetryAttempts': 0}}

Key Parameters

The stop_trigger() method accepts the following parameter:

  • Name (string, required): The name of the trigger to stop

Error Handling

The code includes two types of exception handling:

  • ClientError: Handles AWS service-specific errors (e.g., trigger not found, permission denied)

  • Generic Exception: Catches any unexpected errors during execution

Conclusion

Use the stop_trigger() method with boto3 to programmatically stop AWS Glue triggers. Always include proper error handling to manage AWS service exceptions and ensure your trigger name exists before attempting to stop it.

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

460 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements