如何使用 Python 脚本验证 MFA 删除是否在存储桶列表上

How to verify if MFA delete is on or not on a list of bucket using Python script

你好,我有一个存储桶列表,我想使用 python 脚本验证这些存储桶是否启用了 mfa,但我对 python 了解不多。谁能帮帮我吗。该过程是检查存储桶,然后打印是否启用了 mfa,否则打印它已禁用。谢谢。

import boto3

buckets = ['...']

s3 = boto3.client('s3')

for b in buckets:
    resp = s3.get_bucket_versioning(Bucket=b)
    if mfa:=resp.get('MFADelete'):
        print(f"{b}: MFA delete is {mfa}")
    else:
        print(f"{b}: MFA delete is never configured")