如何使用 Boto3 獲取 AWS Glue 安全性中所有安全配置的詳細資訊?
問題陳述 − 在 Python 中使用 boto3 庫獲取 AWS Glue 安全性中所有安全配置的詳細資訊。
示例 − 獲取 AWS Glue 安全性中所有安全配置的詳細資訊。
解決此問題的方法/演算法
步驟 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}}
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP