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

4 comments:

  1. The only comment I have is that this depends on Amazon's website not changing. I would advise against relying on this for anything you don't run manually.

    Also, the script you're running to govern input in this comment form is blocking the 'Home' and 'End' keys, as well as the arrow keys, and that's extremely frustrating :P

    ReplyDelete
  2. ha, yeah this comment box is really bad, first time I used it, its just the default blogspot.com one. Wont allow holding shift and arrow keys or atl + a either. . ?

    Im kind of hoping amazon wont change the POST and GET commands needed to get the report, however, I will maintain it if they do change something.

    ReplyDelete
  3. Thanks for releasing this script!

    I wrote a script to process xml report after manually uploading it, but this is much better.

    ReplyDelete
  4. Script errors. Any idea?
    PHP Notice: Trying to get property of non-object in C:\sites\lubi\lubi.se\web\tools\AmzonTools.php on line 265
    PHP Warning: Invalid argument supplied for foreach() in C:\sites\lubi\lubi.se\web\tools\AmzonTools.php on line 265
    PHP Notice: Trying to get property of non-object in C:\sites\lubi\lubi.se\web\tools\AmzonTools.php on line 337
    PHP Warning: Invalid argument supplied for foreach() in C:\sites\lubi\lubi.se\web\tools\AmzonTools.php on line 337
    PHP Notice: Trying to get property of non-object in C:\sites\lubi\lubi.se\web\tools\AmzonTools.php on line 337
    PHP Warning: Invalid argument supplied for foreach() in C:\sites\lubi\lubi.se\web\tools\AmzonTools.php on line 337

    ReplyDelete