ข้อกำหนดปัญหา: ใช้ไลบรารี Boto3 ใน Python เพื่อดึงการตั้งค่าความปลอดภัย/การเข้ารหัสของ Catalog
ตัวอย่าง: ดึงการตั้งค่าความปลอดภัย/การเข้ารหัสของ Catalog
ขั้นตอนการแก้ปัญหา
- ขั้นตอน 1: นำเข้า boto3 และ botocore exceptions
- ขั้นตอน 2: catalog_id เป็นพารามิเตอร์ทางเลือก หากไม่ระบุ จะใช้รายละเอียดของบัญชี AWS ของผู้ใช้
- ขั้นตอน 3: สร้าง AWS session ด้วย Boto3
- ขั้นตอน 4: สร้าง AWS client สำหรับ Glue
- ขั้นตอน 5: ใช้ฟังก์ชัน get_data_catalog_encryption_settings ส่ง catalog_id เป็น CatalogId parameter
- ขั้นตอน 6: คืนค่ารายละเอียดการตั้งค่าการเข้ารหัส
- ขั้นตอน 7: จัดการข้อยกเว้นทั่วไป
ตัวอย่างโค้ด
import boto3
from botocore.exceptions import ClientError
def retrieves_encryption_setting(catalog_id=None):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.get_data_catalog_encryption_settings(CatalogId=catalog_id)
return response
except ClientError as e:
raise Exception("boto3 client error in retrieves_encryption_setting: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in retrieves_encryption_setting: " + e.__str__())
print(retrieves_encryption_setting())
ผลลัพธ์
{'DataCatalogEncryptionSettings': {'EncryptionAtRest': {'CatalogEncryptionMode': 'SSE-KMS'}, 'ConnectionPasswordEncryption': {'ReturnConnectionPasswordEncrypted': True}}, 'ResponseMetadata': {'RequestId': '5ffc0dbb***************7c', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 28 Feb 2021 12:22:16 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '166', 'connection': 'keep-alive', 'x-amzn-requestid': '5ffc0dbb********************7c'}, 'RetryAttempts': 0}}