ปัญหา: ใช้ Boto3 ใน Python ดึงข้อมูล Connection ทั้งหมดจาก AWS Glue Data Catalog
ขั้นตอน/อัลกอริทึม
- Import boto3 และ botocore.exceptions.ClientError
- ไม่มีพารามิเตอร์ (ดึงทั้งหมด)
- สร้าง AWS Session และ Glue Client
- เรียก get_connections()
- คืนค่ารายการ Connection Definitions
- จัดการ Exception
ตัวอย่างโค้ด
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', ...}, {'Name': 'dev-ods', ...}], 'ResponseMetadata': {...}}