如何使用 Boto3 获取 AWS Glue 数据目录中的目录的安全配置/加密设置?
问题陈述 - 在 Python 中使用 boto3 库检索目录的安全配置/加密设置。
示例 - 检索目录的安全配置/加密设置。
解决此问题的方法/算法
步骤 1 - 导入 boto3 和 botocore 异常以处理异常。
步骤 2 - catalog_id 是可选参数。如果未提供,则采用用户的 AWS 账户详细信息。
步骤 3 - 使用 boto3 库创建 AWS 会话。确保在默认配置文件中提到了 region_name。如果未提及,则在创建会话时显式传递 region_name。
步骤 4 - 为 Glue 创建 AWS 客户端。
步骤 5 - 现在使用 get_data_catalog_encryption_settings 函数并将 catalog_id 作为 CatalogId 参数传递。
步骤 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}}
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP