如何使用 Boto3 获取 AWS Glue 数据目录中分类器的详细信息?
问题陈述 − 使用 Python 中的 boto3 库从 AWS Glue 数据目录获取分类器的详细信息。例如,获取分类器“xml-test”的详细信息。
解决此问题的方法/算法
步骤 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}}
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP