How can I get the size of an Amazon S3 bucket?

Posted by Garret Heaton on Server Fault See other posts from Server Fault or by Garret Heaton
Published on 2009-11-15T00:40:45Z Indexed on 2012/07/03 9:18 UTC
Read the original article Hit count: 241

I'd like to graph the size (in bytes, and # of items) of an Amazon S3 bucket and am looking for an efficient way to get the data.

The s3cmd tools provide a way to get the total file size using s3cmd du s3://bucket_name, but I'm worried about its ability to scale since it looks like it fetches data about every file and calculates its own sum. Since Amazon charges users in GB-Months it seems odd that they don't expose this value directly.

Although Amazon's REST API returns the number of items in a bucket, [s3cmd] doesn't seem to expose it. I could do s3cmd ls -r s3://bucket_name | wc -l but that seems like a hack.

The Ruby AWS::S3 library looked promising, but only provides the # of bucket items, not the total bucket size.

Is anyone aware of any other command line tools or libraries (prefer Perl, PHP, Python, or Ruby) which provide ways of getting this data?

© Server Fault or respective owner

Related posts about amazon-s3

Related posts about amazon-web-services