如何使用 Boto3 获取 AWS Glue Security 中存在的所有安全配置的详细信息?
问题陈述-使用Python中的boto3库获取AWSGlueSecurity中存在的所有安全配置的详细信息。
示例-获取AWSGlueSecurity中存在的所有安全配置的详细信息。
解决这个问题的方法/算法
步骤1-导入boto3和botocore异常以处理异常。
步骤2-没有参数。它获取用户的AWSGlueSecurity中存在的所有安全配置。
步骤3-使用boto3库创建AWS会话。确保在默认配置文件中提到region_name。如果未提及,则在创建会话时显式传递region_name。
第4步-为胶水创建一个AWS客户端。
第5步-现在使用get_security_configurations函数。
步骤6-它返回所有安全性的配置。
第7步-如果检查作业时出现问题,则处理通用异常。
示例
使用以下代码获取所有安全性的配置-
import boto3
frombotocore.exceptionsimport ClientError
def get_all_security_configuration():
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.get_security_configurations()
return response
except ClientError as e:
raise Exception("boto3 client error in get_all_security_configuration: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in get_all_security_configuration: " + e.__str__())
print(get_all_security_configuration())输出结果{'SecurityConfiguration': {'Name': 'job-security-settings',
'CreatedTimeStamp': datetime.datetime(2020, 9, 24, 1, 53, 21, 265000,
tzinfo=tzlocal()), 'EncryptionConfiguration': {'S3Encryption':
[{'S3EncryptionMode': 'SSE-KMS', 'KmsKeyArn': 'arn:aws:kms:us-east1:**************:key/************-bd27-f3ec3b590d0f'}]}},
'ResponseMetadata': {'RequestId': 'b1***************-afd048ed7d07',
'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Mon, 01 Mar 2021
05:48:47 GMT', 'content-type': 'application/x-amz-json-1.1', 'contentlength': '417', 'connection': 'keep-alive', 'x-amzn-requestid':
'b1*******************-afd048ed7d07'}, 'RetryAttempts': 0}}