如何使用Boto3获取AWS Glue安全性中所有安全配置的详细信息?

如何使用Boto3获取AWS Glue安全性中所有安全配置的详细信息?

问题陈述 − 使用Python中的boto3库获取AWS Glue安全性中所有安全配置的详细信息。

示例 − 获取AWS Glue安全性中所有安全配置的详细信息。

更多Python相关文章,请阅读:Python 教程

解决此问题的方法/算法

第1步 − 导入boto3和botocore异常以处理异常。

第2步 − 没有参数。它会获取用户AWS Glue安全性中存在的所有安全配置。

第3步 − 使用boto3库创建AWS会话。确保默认配置文件中有region_name。如果没有提及,则在创建会话时显式传递region_name。

第4步 − 创建用于glue的AWS客户端。

第5步 − 现在使用get_security_configurations函数。

第6步 − 它会返回所有安全配置的配置。

第7步 − 如果在检查作业时出现错误,则处理通用异常。

示例

使用以下代码获取所有安全配置的配置 –

import boto3
from botocore.exceptions import 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}}

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程