列表版本使用boto3在s3中启用了存储桶

时间:2017-12-21 06:29:08

标签: python amazon-web-services amazon-s3 boto3 s3-bucket

如何列出打开版本标记的所有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)

1 个答案:

答案 0 :(得分:1)

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)