我编写了一个 Python 脚本,试图通过使用AWS Boto 3 list_objects() 方法来确定所有可用 AWS S3 存储桶的总大小。
逻辑很简单:
这是相关的代码片段:
import boto3
s3_client = boto3.client('s3')
# Get all S3 buckets owned by the authenticated sender of the request
buckets = s3_client.list_buckets()
# For each bucket...
for bucket in buckets['Buckets']:
# Get up to first 1,000 objects in bucket
bucket_objects = s3_client.list_objects(Bucket=bucket['Name'])
# Initialize total_size
total_size = 0
# Add size of each individual item in bucket …Run Code Online (Sandbox Code Playgroud) python concurrency multithreading amazon-s3 amazon-web-services