2

如何列出打开版本控制标志的所有 s3 存储桶名称?

我有 100 个 s3 存储桶。一些存储桶打开了版本控制标志。我想使用 boto3 列出所有这些存储桶名称。

我在下面给出了我的 python 代码片段。

import boto3
REGION = "us-east-1"

s3client = boto3.client('s3',region_name=REGION)
for bucket in s3client.list_buckets()['Buckets']:
  bucket = bucket['Name']
  response = s3client.get_bucket_versioning(Bucket=bucket)
  if 'Status' in response and response['Status'] == 'Enabled':
    print(bucket)
4

1 回答 1

5
import boto3

ACCESS = "AKIAI4JYMHUIYKIFABCD"
SECRET = "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"
REGION = "us-east-1"

s3client = boto3.client('s3',aws_access_key_id=ACCESS,aws_secret_access_key=SECRET,region_name=REGION)
for bucket in s3client.list_buckets()['Buckets']:
  bucket = bucket['Name']
  response = s3client.get_bucket_versioning(Bucket=bucket)
  if 'Status' in response and response['Status'] == 'Enabled':
    print(bucket)
于 2017-12-21T06:29:08.347 回答