Skip to content

Instantly share code, notes, and snippets.

@garnaat
Created September 1, 2011 13:15
Show Gist options
  • Save garnaat/1186142 to your computer and use it in GitHub Desktop.
Save garnaat/1186142 to your computer and use it in GitHub Desktop.
Get total bytes in a bucket
# Iterates over all the keys in a bucket and totals the bytes used
# NOTE: if you have a lot of keys, this could take a LONG time.
import boto
def bucket_du(bucket_name):
s3 = boto.connect_s3()
bucket = s3.lookup(bucket_name)
total_bytes = 0
for key in bucket:
total_bytes += key.size
return total_bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment