Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách dùng Boto3 lấy chi tiết tất cả cấu hình bảo mật trong AWS Glue Security

Đề bài − Sử dụng thư viện boto3 trong Python để lấy chi tiết tất cả cấu hình bảo mật có trong AWS Glue Security.

Ví dụ − Lấy chi tiết tất cả cấu hình bảo mật có trong AWS Glue Security.

Cách tiếp cận/Thuật toán giải quyết

Bước 1 − Nhập boto3 và botocore exceptions để xử lý ngoại lệ.

Bước 2 − Không có tham số. Nó lấy tất cả cấu hình bảo mật trong AWS Glue Security của người dùng.

Bước 3 − Tạo phiên AWS bằng thư viện boto3. Đảm bảo region_name được đề cập trong profile mặc định. Nếu không, hãy truyền rõ ràng region_name khi tạo phiên.

Bước 4 − Tạo client AWS cho glue.

Bước 5 − Sử dụng hàm get_security_configurations.

Bước 6 − Nó trả về cấu hình của tất cả bảo mật.

Bước 7 − Xử lý ngoại lệ chung nếu có lỗi xảy ra khi kiểm tra job.

Ví dụ

Sử dụng code sau để lấy cấu hình của tất cả bảo mật:

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())

Kết quả

{'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}}