How to use Boto3 to get the details of a classifier from AWS Glue Data catalog?

Boto3PythonServer Side ProgrammingProgramming

Problem Statement − Use boto3 library in Python to get details of a classifier from AWS Glue Data catalog. For example, get the details of a classifier – ‘xml-test’.

Approach/Algorithm to solve this problem

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

Step 2 − Pass the parameter classifier_name whose details are to be checked.

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 get_classifier and pass the classifier_name as Name parameter.

Step 6 − It will fetch the details of the classifier.

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


Use the following code to get details of a classifier from AWS Glue Data catalog −

import boto3
from botocore.exceptions import ClientError

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



{'Classifier': {'GrokClassifier': {'Name': 'xml-test', 'Classification':
'xml', 'CreationTime': datetime.datetime(2018, 6, 21, 4, 7, 4,
tzinfo=tzlocal()), 'LastUpdated': datetime.datetime(2018, 6, 21, 4, 7,
11, tzinfo=tzlocal()), 'Version': 2, 'GrokPattern': 'SYSLOGTIMESTAMP
%{MONTH} +%{MONTHDAY} %{TIME}'}}, 'ResponseMetadata': {'RequestId':
'c291cce2-………………..-3552077ddefd', 'HTTPStatusCode': 200, 'HTTPHeaders':
{'date': 'Sun, 21 Feb 2021 07:58:09 GMT', 'content-type':
'application/x-amz-json-1.1', 'content-length': '218', 'connection':
'keep-alive', 'x-amzn-requestid': 'c291cce2-……….-3552077ddefd'},
'RetryAttempts': 0}}
Updated on 22-Mar-2021 08:47:15