Amazon::S3 โ A portable client library for working with and managing Amazon S3 buckets and keys.
| Use Case | Command | Description |
|---|---|---|
| ๐ Connect to S3 | Amazon::S3->new({ aws_access_key_id => $key, aws_secret_access_key => $secret }) | Create a new S3 client object |
| ๐ชฃ List buckets | $s3->buckets | Retrieve all buckets for the account |
| โ Create bucket | $s3->add_bucket({ bucket => $name }) | Add a new bucket to the account |
| ๐ Upload key | $bucket->add_key($keyname, $value, { content_type => 'text/plain' }) | Store a key with optional metadata |
| ๐ List keys | $bucket->list | List all keys in a bucket |
| โ Delete key | $bucket->delete_key($keyname) | Remove a key from a bucket |
| ๐๏ธ Delete bucket | $bucket->delete_bucket | Remove an empty bucket |
| ๐ Paginate results | $s3->list_bucket({ bucket => $name, marker => $last_key }) | List keys with pagination support |
#!/usr/bin/perl
use warnings;
use strict;
use Amazon::S3;
use vars qw/$OWNER_ID $OWNER_DISPLAYNAME/;
my $aws_access_key_id = "Fill me in!";
my $aws_secret_access_key = "Fill me in too!";
my $s3 = Amazon::S3->new(
{ aws_access_key_id => $aws_access_key_id,
aws_secret_access_key => $aws_secret_access_key,
retry => 1
}
);
my $response = $s3->buckets;
# create a bucket
my $bucket_name = $aws_access_key_id . '-net-amazon-s3-test';
my $bucket = $s3->add_bucket( { bucket => $bucket_name } )
or die $s3->err . ": " . $s3->errstr;
# store a key with a content-type and some optional metadata
my $keyname = 'testing.txt';
my $value = 'T';
$bucket->add_key(
$keyname, $value,
{ content_type => 'text/plain',
'x-amz-meta-colour' => 'orange',
}
);
# list keys in the bucket
$response = $bucket->list
or die $s3->err . ": " . $s3->errstr;
print $response->{bucket}."\n";
for my $key (@{ $response->{keys} }) {
print "\t".$key->{key}."\n";
}
# delete key from bucket
$bucket->delete_key($keyname);
# delete bucket
$bucket->delete_bucket;
Amazon::S3 provides a portable client interface to Amazon Simple Storage System (S3).
"Amazon S3 is storage for the Internet. It is designed to make web-scale computing easier for developers. Amazon S3 provides a simple web services interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefits on to developers".
To sign up for an Amazon Web Services account, required to use this library and the S3 service, please visit the Amazon Web Services web site at http://www.amazonaws.com/.
You will be billed accordingly by Amazon when you use this module and must be responsible for these costs.
To learn more about Amazon's S3 service, please visit: http://s3.amazonaws.com/.
This need for this module arose from some work that needed to work with S3 and would be distributed, installed and used on many various environments where compiled dependencies may not be an option. Net::Amazon::S3 used XML::LibXML tying it to that specific and often difficult to install option. In order to remove this potential barrier to entry, this module is forked and then modified to use XML::SAX via XML::Simple.
Amazon::S3 is intended to be a drop-in replacement for <Net:Amazon::S3> that trades some performance in return for portability.
Create a new S3 client object. Takes some arguments:
Returns undef on error, else HASHREF of results:
Takes a HASHREF:
Returns 0 on failure or a Amazon::S3::Bucket object on success
Takes a scalar argument, the name of the bucket you're creating
Returns an (unverified) bucket object from an account. This method does not access the network.
Takes either a Amazon::S3::Bucket object or a HASHREF containing
Returns false (and fails) if the bucket isn't empty.
Returns true if the bucket is successfully deleted.
List all keys in this bucket.
Takes a HASHREF of arguments:
Returns undef on error and a HASHREF of data on success:
The HASHREF looks like this:
{
bucket => $bucket_name,
prefix => $bucket_prefix,
marker => $bucket_marker,
next_marker => $bucket_next_available_marker,
max_keys => $bucket_max_keys,
is_truncated => $bucket_is_truncated_boolean
keys => [$key1,$key2,...]
}
Explanation of bits of that:
Each key is a HASHREF that looks like this:
{
key => $key,
last_modified => $last_mod_date,
etag => $etag, # An MD5 sum of the stored content.
size => $size, # Bytes
storage_class => $storage_class
owner_id => $owner_id,
owner_displayname => $owner_name
}
List all keys in this bucket without having to worry about 'marker'. This is a convenience method, but may make multiple requests to S3 under the hood.
Takes the same arguments as list_bucket.
This module contains code modified from Amazon that contains the following notice:
# This software code is made available "AS IS" without warranties of any
# kind. You may copy, display, modify and redistribute the software
# code either by itself or as incorporated into your code; provided that
# you do not remove any proprietary notices. Your use of this software
# code is at your own risk and you waive any claim against Amazon
# Digital Services, Inc. or its affiliates with respect to your use of
# this software code. (c) 2006 Amazon Digital Services, Inc. or its
# affiliates.
Testing S3 is a tricky thing. Amazon wants to charge you a bit of money each time you use their service. And yes, testing counts as using. Because of this, the application's test suite skips anything approaching a real test unless you set these three environment variables:
Bugs should be reported via the CPAN bug tracker at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Amazon-S3>
For other issues, contact the author.
Timothy Appnel <tima AT cpan.org>
This module was initially based on Net::Amazon::S3 0.41, by Leon Brocard. Net::Amazon::S3 was based on example code from Amazon with this notice:
# This software code is made available "AS IS" without warranties of any
# kind. You may copy, display, modify and redistribute the software
# code either by itself or as incorporated into your code; provided that
# you do not remove any proprietary notices. Your use of this software
# code is at your own risk and you waive any claim against Amazon
# Digital Services, Inc. or its affiliates with respect to your use of
# this software code. (c) 2006 Amazon Digital Services, Inc. or its
# affiliates.
The software is released under the Artistic License. The terms of the Artistic License are described at http://www.perl.com/language/misc/Artistic.html. Except where otherwise noted, Amazon::S3 is Copyright 2008, Timothy Appnel, tima AT cpan.org. All rights reserved.
Generated by phpman v4.9.22-1-g1b0fcb4 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-05 09:01 @216.73.216.52
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format