Python 如何使用Boto3获取AWS Glue数据目录中所有分类器的详细信息?
问题陈述:使用Python中的boto3库来获取AWS Glue数据目录中所有分类器的详细信息。例如,从用户账户中获取所有分类器的详细信息。
阅读更多:Python 教程
解决此问题的方法/算法
第1步 - 导入boto3库和botocore异常来处理异常。
第2步 - 没有任何参数。
第3步 - 使用boto3库创建一个AWS会话。确保在默认配置文件中提供region_name参数。如果没有提供,那么在创建会话时需要明确指定region_name参数。
第4步 - 创建一个glue AWS客户端。
第5步 - 调用 get_classifiers 方法。
第6步 - 它将获取AWS Glue数据目录中所有可用分类器的详细信息。
第7步 - 如果在检查任务时出现问题,则要处理常规异常。
示例
使用以下代码获取AWS Glue数据目录中所有分类器的详细信息:
import boto3
from botocore.exceptions import ClientError
def get_all_classifier_details():
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.get_classifiers()
return response
except ClientError as e:
raise Exception("boto3 client error in get_all_classifier_details: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in get_all_classifier_details: " + e.__str__())
print(get_all_classifier_details())
输出
{'Classifiers': [
{'XMLClassifier': {'Name': 'aiml-linkup', 'Classification': 'xml',
'CreationTime': datetime.datetime(2020, 4, 17, 13, 26, 50,
tzinfo=tzlocal()), 'LastUpdated': datetime.datetime(2020, 4, 17, 13, 26,
50, tzinfo=tzlocal()), 'Version': 1, 'RowTag': 'job'}},
{'XMLClassifier': {'Name': 'aiml-test1', 'Classification': 'xml',
'CreationTime': datetime.datetime(2019, 10, 7, 20, 48, 44,
tzinfo=tzlocal()), 'LastUpdated': datetime.datetime(2019, 10, 7, 20, 48,
44, tzinfo=tzlocal()), 'Version': 1, 'RowTag': 'nitf'}},
{'GrokClassifier': {'Name': 'classifier1', 'Classification':
'classifier1', '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}'}}, {'CsvClassifier': {'Name': 'csvquotes', 'CreationTime': datetime.datetime(2020, 9, 10, 5, 6, 29,
tzinfo=tzlocal()), 'LastUpdated': datetime.datetime(2020, 9, 10, 5, 6,
29, tzinfo=tzlocal()), 'Version': 1, 'Delimiter': ',', 'QuoteSymbol':
'"', 'ContainsHeader': 'UNKNOWN', 'DisableValueTrimming': False,
'AllowSingleColumn': False}},
{'XMLClassifier': {'Name': 'xml-test', 'Classification': 'xml',
'CreationTime': datetime.datetime(2020, 4, 10, 18, 26, 50,
tzinfo=tzlocal()), 'LastUpdated': datetime.datetime(2020, 4, 15, 0, 3,
8,tzinfo=tzlocal()), 'Version': 2, 'RowTag': 'job'}}],
'ResponseMetadata': {'RequestId': '7fa7a78e-…………e4261bfd1',
'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 21 Feb 2021
08:02:30 GMT', 'content-type': 'application/x-amz-json-1.1', 'contentlength': '885', 'connection': 'keep-alive', 'x-amzn-requestid':
'7fa7a78e-……………..e4261bfd1'}, 'RetryAttempts': 0}}
极客教程