Tying Perl hashes to Amazon S3 buckets
Sunday, December 16th, 2007As mentioned last time, I released my first Perl module to the CPAN, called Tie::Amazon::S3. What it does is rather simple: it allows one to treat an Amazon S3 bucket as a Perl hash, like so:
use Tie::Amazon::S3;
tie my %bucket, 'Tie::Amazon::S3', $my_aws_id, $my_aws_passwd, $my_s3_bucket;
# read a remote file to a scalar
my $textfile = $bucket{textfile};
# write some text to a key
$bucket{'songs/freesoftwaresong/list'} = <<EOF;
freesoftwaresong.au
jonobacon-freesoftwaresong.ogg
Fenster-FreeSoftwareSong.ogg
EOF
Tie::Amazon::S3 builds on top of Leon Brocard’s Net::Amazon::S3 module, so one can still do other actions such as setting a key’s ACL by accessing the tied(%bucket).
Today I made another version of that module, completing the hash abstraction by implementing some missing methods, allowing one to iterate through the list of available keys in the bucket (e.g. foreach keys %bucket and such.)
As mentioned, it can be found on the CPAN, but I also have a git tree up. Helpful comments & patches are welcome!