如何使用Boto3从AWS Glue数据目录中获取分类器的详细信息?

如何使用Boto3从AWS Glue数据目录中获取分类器的详细信息?

问题陈述 − 使用Python中的Boto3库从AWS Glue数据目录中获取分类器的详细信息。例如,获取分类器’xml-test’的详细信息。

更多Python相关文章,请阅读:Python 教程

解决此问题的方法/算法

步骤1 − 导入Boto3和botocore异常来处理异常。

步骤2 − 传递参数 classifier_name ,其详细信息需要检查。

步骤3 − 使用Boto3库创建AWS会话。确保在默认配置文件中指定了region_name。如果没有指定,则在创建会话时显式传递region_name。

步骤4 − 为glue创建AWS客户端。

步骤5 − 调用 get_classifier ,并将 classifier_name 作为Name参数传递。

步骤6 − 它将获取分类器的详细信息。

步骤7 − 如果在检查作业时发生了错误,请处理通用异常。

示例

使用以下代码从AWS Glue数据目录获取分类器的详细信息−

import boto3
from botocore.exceptions import ClientError

def get_classifier_details(classifier_name):
   session = boto3.session.Session()
   glue_client = session.client('glue')
   try:
      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__())

print(get_classifier_details("xml-test"))

输出

{'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}}

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程