如何使用 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