• Stars
    star
    5
  • Rank 2,856,727 (Top 57 %)
  • Language
    Perl
  • Created about 10 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight interface to Amazon S3 (Simple Storage Service)

NAME

AWS::S3 - Lightweight interface to Amazon S3 (Simple Storage Service)

<a href='https://travis-ci.org/leejo/AWS-S3?branch=master'><img src='https://travis-ci.org/leejo/AWS-S3.svg?branch=master' /></a>
<a href='https://coveralls.io/r/leejo/AWS-S3?branch=master'><img src='https://coveralls.io/repos/leejo/AWS-S3/badge.png?branch=master' alt='Coverage Status' /></a>

SYNOPSIS

use AWS::S3;

my $s3 = AWS::S3->new(
  access_key_id     => 'E654SAKIASDD64ERAF0O',
  secret_access_key => 'LgTZ25nCD+9LiCV6ujofudY1D6e2vfK0R4GLsI4H',
  honor_leading_slashes => 0, # set to allow leading slashes in bucket names, defaults to 0
);

# Add a bucket:
my $bucket = $s3->add_bucket(
  name    => 'foo-bucket',
);

# Set the acl:
$bucket->acl( 'private' );

# Add a file:
my $new_file = $bucket->add_file(
  key       => 'foo/bar.txt',
  contents  => \'This is the contents of the file',
);

# You can also set the contents with a coderef:
# Coderef should eturn a reference, not the actual string of content:
$new_file = $bucket->add_file(
  key       => 'foo/bar.txt',
  contents  => sub { return \"This is the contents" }
);

# Get the file:
my $same_file = $bucket->file( 'foo/bar.txt' );

# Get the contents:
my $scalar_ref = $same_file->contents;
print $$scalar_ref;

# Update the contents with a scalar ref:
$same_file->contents( \"New file contents" );

# Update the contents with a code ref:
$same_file->contents( sub { return \"New file contents" } );

# Delete the file:
$same_file->delete();

# Iterate through lots of files:
my $iterator = $bucket->files(
  page_size   => 100,
  page_number => 1,
);
while( my @files = $iterator->next_page )
{
  warn "Page number: ", $iterator->page_number, "\n";
  foreach my $file ( @files )
  {
    warn "\tFilename (key): ", $file->key, "\n";
    warn "\tSize: ", $file->size, "\n";
    warn "\tETag: ", $file->etag, "\n";
    warn "\tContents: ", ${ $file->contents }, "\n";
  }# end foreach()
}# end while()

# You can't delete a bucket until it's empty.
# Empty a bucket like this:
while( my @files = $iterator->next_page )
{
  map { $_->delete } @files;

  # Return to page 1:
  $iterator->page_number( 1 );
}# end while()

# Now you can delete the bucket:
$bucket->delete();

DESCRIPTION

AWS::S3 attempts to provide an alternate interface to the Amazon S3 Simple Storage Service.

NOTE: Until AWS::S3 gets to version 1.000 it will not implement the full S3 interface.

Disclaimer: Several portions of AWS::S3 have been adopted from Net::Amazon::S3.

NOTE: AWS::S3 is NOT a drop-in replacement for Net::Amazon::S3.

TODO: CloudFront integration.

CONSTRUCTOR

Call new() with the following parameters.

access_key_id

Required. String.

Provided by Amazon, this is your access key id.

secret_access_key

Required. String.

Provided by Amazon, this is your secret access key.

secure

Optional. Boolean.

Default is 0

endpoint

Optional. String.

Default is s3.amazonaws.com

ua

Optional. Should be an instance of LWP::UserAgent or a subclass of it.

Defaults to creating a new instance of LWP::UserAgent::Determined

honor_leading_slashes

Optional. Boolean to set if bucket names should include any leading slashes when sent to S3 - defaults to zero

PUBLIC PROPERTIES

access_key_id

String. Read-only

secret_access_key

String. Read-only.

secure

Boolean. Read-only.

endpoint

String. Read-only.

ua

LWP::UserAgent object. Read-only.

owner

AWS::S3::Owner object. Read-only.

PUBLIC METHODS

buckets

Returns an array of AWS::S3::Bucket objects.

bucket( $name )

Returns the AWS::S3::Bucket object matching $name if found.

Returns nothing otherwise.

add_bucket( name => $name, location => 'us-west-1' )

Attempts to create a new bucket with the name provided. The location parameter is optional and, as per the AWS docs, will default to "us-east-1".

On success, returns the new AWS::S3::Bucket

On failure, dies with the error message.

See AWS::S3::Bucket for details on how to use buckets (and access their files).

SEE ALSO

The Amazon S3 API Documentation

AWS::S3::Bucket

AWS::S3::File

AWS::S3::FileIterator

AWS::S3::Owner

AUTHOR

Originally John Drago [email protected], currently maintained by Lee Johnson (LEEJO) [email protected] with contributions from Evan Carroll, Robin Clarke, Ulrich Kautz, simbabque, Dave Rolsky

LICENSE

This software is Free software and may be used and redistributed under the same terms as any version of perl itself.

Copyright John Drago 2011 all rights reserved.

More Repositories

1

CGI.pm

The CGI.pm perl module
Perl
34
star
2

cgi-alternatives

Documentation for "modern" alternatives to CGI.pm
Perl
8
star
3

html-packer-perl

CPAN Module HTML::Packer
Perl
8
star
4

git-tools

Moving my git tools into their own repository
Ruby
7
star
5

string-crc32

Perl interface for cyclic redundency check generation
XS
7
star
6

battling_a_legacy_schema_with_dbic

A talk planned for 2016 YAPC::{NA,EU} and possibly others
HTML
6
star
7

cgi-fast

The new home for CGI::Fast, removing it from the original CGI.pm distribution
Perl
4
star
8

javascript-packer-perl

CPAN Module Javascript::Packer
JavaScript
3
star
9

perl_memory_talk

A short talk on tracking down some memory leaks in a perl application
HTML
3
star
10

oauth2_and_mojolicious

Planned talk on OAuth2 support with Mojolicious
Perl
3
star
11

a_few_git_bits

for a short talk at YAPC::EU 2016
Groff
3
star
12

geo-ip2location-lite-p6

Geo::IP2Location::Lite - Lightweight lookup of IPv4 address details using BIN files from http://www.ip2location.com
Perl 6
2
star
13

css-packer-perl

CPAN Module CSS::Packer
Perl
2
star
14

emulation_driven_development

Lightning talk about emulation driven development, sort of like TDD for the brave new world of REST APIs
2
star
15

regexp-reggrp-perl

CPAN Module Regexp::RegGrp
Perl
1
star
16

using_mojolicious_for_fun_and_nonprofit

Planned talk on Mojolicious
Perl
1
star
17

find_and_fix_with_burp_scanner

โ€ŽFind and fix your web security vulnerabilities with Burp Scannerโ€Ž
Perl
1
star
18

perl_events

scripts and such for the perl_events Instagram account
Python
1
star
19

oauth2_is_done

A talk planned for YAPC::EU 2017, TPC 2017, SPW 2017, and LJP 2017
HTML
1
star
20

emulating_any_api

A lightning talk on JSON::Schema::ToJSON and how it can be used to emulate any API
HTML
1
star
21

leejo.github.io

HTML
1
star
22

twenty_six_different_endings

An idea for a talk i will give if i can complete the task at hand
1
star
23

perl6_example

perl6 examples!
Perl 6
1
star
24

business-monzo

Perl library for interacting with the Mondo API
Perl
1
star