Tuesday, December 8, 2009

First alpha release

I needed a way to get the size of my buckets in Amazon S3 in PHP.

Unfortunately Amazon does not provide the ability to get the sizes of buckets in their API.

The only way I was able to get the size was by using this Amazon S3 PHP Class to loop over every object and add up the size. This took way to long, especially with buckets that have a lot of objects.

By googling and playing around I was able manually calculate the size of a bucket by using the information in the Usage Reports from the AWS Portal.

This led me to create a basic PHP script to log in to the AWS Portal and grab the report, and then calculate the sizes for each bucket. As a side feature this also allows you to log in to (Almost?) any Amazon service with PHP, so has the potential to automate a lot more with Amazon.

From there the class has grown and can be used to grab information about each bucket such as month of storage, monthly data transfer in, month data transfer out, PUT, COPY, POST, or LIST requests, GET and all other requests and allows you to calculate the cost of each bucket.

It can also do the original function I set out to achieve. Get the size of a bucket at a given time period.

This class does not use Amazons S3 API, it only downloads the XML or CSV report from AWS Portal. It also does not take into account where your bucket is. You do NOT need to enable bucket logging for this to work.

This class is very alpha and hasn’t had much testing. Suggestions, bug reports, feature suggestion or patches are welcome.

Dowload the AmazonTools class