How to use Boto3 to delete a workflow from AWS Data Catalog?

When a user wants to delete a workflow from AWS Data catalog.

Example − Delete a workflow ‘test’ from your account.

Problem Statement − Use boto3 library in Python to delete a workflow that is available in your account.

Approach/Algorithm to solve this problem

Step 1 − Import boto3 and botocore exceptions to handle exceptions.

Step 2 − Pass the parameter workflow_name that should be deleted from AWS Glue Catalog.

Step 3 − Create an AWS session using boto3 library. Make sure region_name is mentioned in default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.

Step 4 − Create an AWS client for glue.

Step 5 − Call delete_workflow and pass the workflow_name as Name parameter.

Step 6 − It will delete the workflow and return the response metadata. Please note, if workflow is not found in AWS Data Catalog, it doesn’t throw any exception.

Step 7 − Handle the generic exception if something went wrong while checking the job.


Use the following code to delete a workflow listed in user account −

import boto3
from botocore.exceptions import ClientError

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



{'Name': 'test, 'ResponseMetadata': {'RequestId': '………..-………………….-
59a9bc817e0f', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 21
Feb 2021 05:37:11 GMT', 'content-type': 'application/x-amz-json-1.1',
'content-length': '35', 'connection': 'keep-alive', 'x-amzn-requestid':
…………………….-59a9bc817e0f'}, 'RetryAttempts': 0}}