如何使用 Boto3 獲取 AWS Glue 資料目錄中所有可用連線的詳細資訊?
問題陳述 − 使用 Python 中的 boto3 庫獲取 AWS Glue 資料目錄中所有現有連線的詳細資訊。
示例 − 獲取所有連線定義的詳細資訊。
解決此問題的方法/演算法
步驟 1 − 匯入 boto3 和 botocore 異常以處理異常。
步驟 2 − 沒有引數。
步驟 3 − 使用 boto3 庫建立 AWS 會話。確保在預設配置檔案中提到了region_name。如果未提及,則在建立會話時顯式傳遞region_name。
步驟 4 − 為 Glue 建立 AWS 客戶端。
步驟 5 − 呼叫get_connections 函式。
步驟 6 − 它將從 AWS Glue 資料目錄中獲取連線定義的詳細資訊。
步驟 7 − 如果在檢查作業時出現問題,請處理通用異常。
示例
使用以下程式碼獲取 AWS Glue 資料目錄中所有連線的定義:
import boto3
from botocore.exceptions import ClientError
def get_details_of_all_connections():
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.get_connections()
return response
except ClientError as e:
raise Exception("boto3 client error in get_details_of_all_connections: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in get_details_of_all_connections: " + e.__str__())
print(get_details_of_all_connections())輸出
{'ConnectionList': [
{'Name': '01_Daily', 'Description': '', 'ConnectionType': 'JDBC',
'ConnectionProperties': {'JDBC_CONNECTION_URL':
'jdbc:redshift://**********.us-east-1.redshift.amazonaws.com:5439/abc',
'JDBC_ENFORCE_SSL': 'false', 'PASSWORD': '!*******', 'USERNAME':
'********'}, 'PhysicalConnectionRequirements': {'SubnetId': 'subneta******e', 'SecurityGroupIdList': ['sg-********3'], 'AvailabilityZone':
'us-east-1a'}, 'CreationTime': datetime.datetime(2020, 12, 11, 17, 1,
51, 519000, tzinfo=tzlocal()), 'LastUpdatedTime':
datetime.datetime(2020, 12, 11, 17, 1, 51, 519000, tzinfo=tzlocal())},
{'Name': 'aurora-poc', 'ConnectionType': 'JDBC', 'ConnectionProperties':
{'JDBC_CONNECTION_URL': 'jdbc:postgresql://**********-cluster.clustercv********6p.us-east-1.rds.amazonaws.com:5432/*******,
'JDBC_ENFORCE_SSL': 'false', 'PASSWORD': '******', 'USERNAME': user'},
'PhysicalConnectionRequirements': {'SubnetId': 'subnet-35******e',
'SecurityGroupIdList': ['sg-*******d', 'sg-0***********'],
'AvailabilityZone': 'us-east-1c'}, 'CreationTime':
datetime.datetime(2020, 11, 18, 12, 38, 29, 625000, tzinfo=tzlocal()),
'LastUpdatedTime': datetime.datetime(2020, 11, 18, 12, 51, 16, 59000,
tzinfo=tzlocal())},
{'Name': 'dev-ods', 'ConnectionType': 'JDBC', 'ConnectionProperties':
{'JDBC_CONNECTION_URL': 'jdbc:postgresql://*****************.us-east1.rds.amazonaws.com:5432/store', 'JDBC_ENFORCE_SSL': 'false',
'PASSWORD': '***********', 'USERNAME': user'},
'PhysicalConnectionRequirements': {'SubnetId': 'subnet-a********',
'SecurityGroupIdList': ['sg-*********b7', 'sg-a8********e'],
'AvailabilityZone': 'us-east-1a'}, 'CreationTime':
datetime.datetime(2020, 5, 27, 3, 10, 24, 538000, tzinfo=tzlocal()),
'LastUpdatedTime': datetime.datetime(2021, 2, 26, 5, 50, 53, 991000,
tzinfo=tzlocal())},],
'ResponseMetadata': {'RequestId': '58bae80d-*******************87',
'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 28 Feb 2021
11:21:55 GMT', 'content-type': 'application/x-amz-json-1.1', 'contentlength': '11568', 'connection': 'keep-alive', 'x-amzn-requestid':
'58bae80d-************************87'}, 'RetryAttempts': 0}}
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP