如何使用 Boto3 获取 AWS Glue Security 中指定安全配置的详细信息?
问题陈述 − 使用 Python 中的 boto3 库获取 AWS Glue Security 中指定安全配置的详细信息。
示例 − 获取 AWS Glue Security 中指定安全配置('job-security-settings')的详细信息。
解决此问题的方法/算法
步骤 1 − 导入 boto3 和 botocore 异常以处理异常。
步骤 2 − security_name 是必须的参数,需要获取其配置详细信息。
步骤 3 − 使用 boto3 库创建 AWS 会话。确保在默认配置文件中提到了region_name。如果未提及,则在创建会话时显式传递region_name。
步骤 4 − 为 Glue 创建 AWS 客户端。
步骤 5 − 现在使用 get_security_configuration 函数并将security_name作为 Name 参数传递。
步骤 6 − 它返回给定安全的配置。
步骤 7 − 如果在检查作业时出现问题,则处理通用异常。
示例
使用以下代码获取给定安全的配置:
import boto3
from botocore.exceptions import ClientError
def get_detail_security_configuration(security_name):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.get_security_configuration(Name=security_name)
return response
except ClientError as e:
raise Exception("boto3 client error in get_detail_security_configuration: " + e.__str__())
except Exception as e:
raise Exception( "Unexpected error in get_detail_security_configuration: " + e.__str__())
print(get_detail_security_configuration("job-security-settings"))输出
{'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}}
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP