문제 설명 − Python에서 boto3 라이브러리를 사용하여 AWS Glue 데이터 카탈로그에서 분류자의 세부 정보를 가져옵니다. 예를 들어 'xml-test'라는 분류자의 세부 정보를 가져옵니다.
이 문제를 해결하기 위한 접근 방식/알고리즘
1단계 − boto3 및 botocore 예외를 가져와 예외를 처리합니다.
2단계 − classifier_name 매개변수 전달 세부 정보를 확인할 대상입니다.
3단계 − boto3 라이브러리를 사용하여 AWS 세션을 생성합니다. region_name이 기본 프로필에 언급되어 있는지 확인하십시오. 언급되지 않은 경우 세션을 생성하는 동안 region_name을 명시적으로 전달하십시오.
4단계 − 글루용 AWS 클라이언트를 생성합니다.
5단계 − get_classifier 호출 classifier_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}}