-
-
Save nirbhabbarat/3554a92f5c586599f21111c9767d49b8 to your computer and use it in GitHub Desktop.
Example Python for get S3 Bucket Size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# This is how I used to write Python scripts. I'm trying to improve: | |
# https://github.com/joehack3r/aws/blob/master/scripts/s3/getS3BucketSize.py | |
import argparse | |
import boto | |
# Arguments | |
parser = argparse.ArgumentParser(description='Calcualte S3 bucket size in GB') | |
parser.add_argument('--buckets', action='store', nargs='+', metavar='<S3 Bucket Name>', dest='s3Buckets', help='S3 buckets to calculate size') | |
args = parser.parse_args() | |
for bucket in args.s3Buckets: | |
s3bucket = boto.s3.connection.S3Connection().get_bucket(bucket) | |
size = 0 | |
for key in s3bucket.list(): | |
size += key.size | |
print "%s:%d B:%.1f KiB:%.1f MiB:%.1f GiB" % (bucket, size, size*1.0/1024, size*1.0/1024/1024, size*1.0/1024/1024/1024) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment