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

问题描述 投票:0回答:1

如何列出打开版本标志的所有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)
python amazon-web-services amazon-s3 boto3 s3-bucket
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.