Amazon-S3
view release on metacpan or search on metacpan
share/README.md view on Meta::CPAN
* [DESCRIPTION](#description)
* [AUTHENTICATION AND CREDENTIALS](#authentication-and-credentials)
* [CHECKSUMS](#checksums)
* [Uploads](#uploads)
* [Downloads](#downloads)
* [WORKING WITH BUCKETS AND OBJECTS](#working-with-buckets-and-objects)
* [Creating and Representing Buckets](#creating-and-representing-buckets)
* [LISTING OBJECTS](#listing-objects)
* [Choosing a Listing API](#choosing-a-listing-api)
* [Prefixes and Delimiters](#prefixes-and-delimiters)
* [Pagination](#pagination)
* [Listing Results](#listing-results)
* [MULTIPART UPLOADS](#multipart-uploads)
* [DIRECTORY BUCKETS](#directory-buckets)
* [ERROR HANDLING](#error-handling)
* [METHODS AND SUBROUTINES](#methods-and-subroutines)
* [CONSTRUCTOR](#constructor)
* [new](#new)
* [ACCESSORS](#accessors)
* [buffer\_size](#buffer\size)
* [cache\_signer](#cache\signer)
* [checksum\_algorithm](#checksum\algorithm)
* [checksum\_types](#checksum\types)
* [credentials](#credentials)
* [dns\_bucket\_names](#dns\bucket\names)
* [err](#err)
* [error](#error)
* [errstr](#errstr)
* [host](#host)
* [last\_request](#last\request)
* [last\_response](#last\response)
* [logger](#logger)
* [retry](#retry)
* [secure](#secure)
* [timeout](#timeout)
* [verify\_checksums](#verify\checksums)
* [AUTHENTICATION AND CONFIGURATION METHODS](#authentication-and-configuration-methods)
* [get\_credentials](#get\credentials)
* [get\_default\_region](#get\default\region)
* [get\_logger](#get\logger)
* [level](#level)
* [region](#region)
* [signer](#signer)
* [BUCKET MANAGEMENT](#bucket-management)
* [add\_bucket](#add\bucket)
* [bucket](#bucket)
* [buckets](#buckets)
* [bucketv2](#bucketv2)
* [delete\_bucket](#delete\bucket)
* [delete\_public\_access\_block](#delete\public\access\block)
* [empty\_bucket](#empty\bucket)
* [get\_bucket\_location](#get\bucket\location)
* [list\_directory\_buckets](#list\directory\buckets)
* [OBJECT LISTING AND VERSIONING](#object-listing-and-versioning)
* [list\_bucket](#list\bucket)
* [list\_bucket\_v2](#list\bucket\v2)
* [list\_bucket\_all\_v2](#list\bucket\all\v2)
* [list\_object\_versions](#list\object\versions)
* [turn\_off\_special\_retry](#turn\off\special\retry)
* [turn\_on\_special\_retry](#turn\on\special\retry)
* [LOGGING AND DEBUGGING](#logging-and-debugging)
* [S3-COMPATIBLE SERVICES](#s3-compatible-services)
* [COMPARISON TO OTHER PERL S3 MODULES](#comparison-to-other-perl-s3-modules)
* [COMPATIBILITY AND LIMITATIONS](#compatibility-and-limitations)
* [Minimum Perl Version](#minimum-perl-version)
* [Signature Version 4](#signature-version-4)
* [Directory Buckets](#directory-buckets)
* [TESTING](#testing)
* [SUPPORT](#support)
* [REPOSITORY](#repository)
* [AUTHOR](#author)
* [SEE ALSO](#see-also)
* [LICENCE](#licence)
# NAME
Amazon::S3 - A Perl client library for working with and managing
Amazon S3 buckets and objects.
# SYNOPSIS
use Amazon::S3;
my $s3 = Amazon::S3->new(
{ credentials => $credentials,
region => 'us-east-1',
}
);
my $bucket = $s3->bucket('example-bucket');
$bucket->add_key(
'testing.txt',
'T',
{ content_type => 'text/plain',
'x-amz-meta-colour' => 'orange',
}
);
my $response = $bucket->list
or die $s3->err . ': ' . $s3->errstr;
for my $key ( @{ $response->{keys} } ) {
print $key->{key} . "\n";
}
my $object = $bucket->get_key('testing.txt')
or die $s3->err . ': ' . $s3->errstr;
print $object->{value};
# DESCRIPTION
`Amazon::S3` provides a Perl interface to Amazon Simple Storage
Service (S3).
The distribution separates account-level S3 operations from
bucket and object operations.
`Amazon::S3` represents the S3 client and AWS account context. It
manages credentials, request signing, regions, service endpoints,
bucket creation and discovery, and account-level listing operations.
share/README.md view on Meta::CPAN
AWS access key ID.
This option is required when a `credentials` object is not supplied.
When explicit credentials are supplied, `Amazon::S3` stores them
internally for use when signing requests. Applications should avoid
dumping the client object to logs.
See ["AUTHENTICATION AND CREDENTIALS"](#authentication-and-credentials).
- aws\_secret\_access\_key
AWS secret access key.
This option is required when a `credentials` object is not supplied.
See ["AUTHENTICATION AND CREDENTIALS"](#authentication-and-credentials).
- buffer\_size
Default buffer size, in bytes, used by operations that stream object
data.
The default is 4096.
- cache\_signer
When true, retain and reuse the Signature Version 4 signer.
When false, construct a signer when one is needed.
The default is false.
See ["AUTHENTICATION AND CREDENTIALS"](#authentication-and-credentials).
- checksum\_algorithm
Checksum algorithm used when `Amazon::S3` supplies a checksum with an
upload.
The default is `crc64nvme`.
Recognized S3 checksum algorithm names are validated by the
constructor. Local checksum implementations provided by this release
are described in ["CHECKSUMS"](#checksums).
- credentials
Credentials provider object.
The object must provide:
get_aws_access_key_id()
get_aws_secret_access_key()
get_token()
[Amazon::Credentials](https://metacpan.org/pod/Amazon%3A%3ACredentials) is one implementation of this interface.
See ["AUTHENTICATION AND CREDENTIALS"](#authentication-and-credentials).
- debug
Compatibility option that sets the default logger level to `debug`.
Applications should normally use `level` instead.
This option affects the internally created logger only.
- dns\_bucket\_names
Controls whether virtual-hosted-style bucket names are used when
possible.
The default is true.
A bucket name that cannot be used as a DNS subdomain is placed in the
request path instead.
- endpoint\_url
Optional explicit S3 service endpoint.
When `endpoint_url` is supplied, `Amazon::S3` uses that endpoint as
specified and does not rewrite the host when the configured region
changes.
The `region` setting still controls the AWS signing region.
This is useful for S3-compatible services, local test environments, and
other cases where the caller must select the service endpoint explicitly.
For example:
my $s3 = Amazon::S3->new(
{ endpoint_url => 'http://localhost:4566',
region => 'us-east-1',
...
}
);
When `endpoint_url` is not supplied, `Amazon::S3` may derive the
standard AWS S3 endpoint from the configured region.
`endpoint_url` and `host` may not both be supplied.
- host
S3 service endpoint.
The default is `s3.amazonaws.com`.
When `region()` is set and the host is a standard Amazon S3 endpoint,
`Amazon::S3` adjusts the host for the configured region.
This option can also be used with S3-compatible and local testing
services.
- level
Logging level used when `Amazon::S3` creates its default logger.
The default is `error`.
See ["LOGGING AND DEBUGGING"](#logging-and-debugging).
- logger
Logger object.
If omitted, `Amazon::S3::Logger` is used.
A caller-supplied logger is expected to provide the logging methods
used by `Amazon::S3`.
See ["LOGGING AND DEBUGGING"](#logging-and-debugging).
- raise\_error
When true, S3 request failures that would normally be reported through
the return value and the `err()`, `errstr()`, and `error()` accessors
instead throw an exception.
The exception includes the HTTP status and, when available, the S3
error code and message.
The default is false for backward compatibility.
See ["ERROR HANDLING"](#error-handling).
- region
AWS region used for account-level requests and as the default region
for newly constructed bucket objects.
The default is `us-east-1`.
- retry
When true, use retry-aware HTTP handling.
Retries use exponential delays of 1, 2, 4, 8, 16, and 32 seconds.
The default is false.
- secure
When true, use HTTPS when communicating with the service.
The default is true.
- signer
Optional Signature Version 4 signer object.
When supplied, this signer is used instead of constructing one from
the configured credentials.
See ["AUTHENTICATION AND CREDENTIALS"](#authentication-and-credentials).
- timeout
HTTP request timeout in seconds.
The default is 30.
- token
Optional AWS session token used with temporary credentials.
- verify\_checksums
Controls checksum verification when downloading objects.
The default is true.
share/README.md view on Meta::CPAN
my $enabled = $s3->dns_bucket_names;
$s3->dns_bucket_names($boolean);
Gets or sets whether virtual-hosted-style bucket addressing is used
when possible.
The constructor default is true.
### err
Returns the most recent S3 error code or short error identifier.
See ["ERROR HANDLING"](#error-handling).
### error
Returns the most recent parsed structured error response.
See ["ERROR HANDLING"](#error-handling).
### errstr
Returns the most recent human-readable error message.
See ["ERROR HANDLING"](#error-handling).
### host
my $host = $s3->host;
$s3->host($endpoint);
Gets or sets the configured S3 endpoint.
The constructor default is `s3.amazonaws.com`.
See ["S3-COMPATIBLE SERVICES"](#s3-compatible-services).
### last\_request
Returns the most recent [HTTP::Request](https://metacpan.org/pod/HTTP%3A%3ARequest) generated by `Amazon::S3`.
See ["ERROR HANDLING"](#error-handling).
### last\_response
Returns the most recent [HTTP::Response](https://metacpan.org/pod/HTTP%3A%3AResponse) received by `Amazon::S3`.
See ["ERROR HANDLING"](#error-handling).
### logger
my $logger = $s3->logger;
$s3->logger($logger);
Gets or sets the logger used by `Amazon::S3`.
See ["LOGGING AND DEBUGGING"](#logging-and-debugging).
### retry
my $retry = $s3->retry;
$s3->retry($boolean);
Gets or sets whether retry-aware HTTP handling is enabled.
The constructor default is false.
### secure
my $secure = $s3->secure;
$s3->secure($boolean);
Gets or sets whether HTTPS is used.
The constructor default is true.
### timeout
my $timeout = $s3->timeout;
$s3->timeout($seconds);
Gets or sets the HTTP request timeout in seconds.
The constructor default is 30.
### verify\_checksums
my $verify_checksums = $s3->verify_checksums;
$s3->verify_checksums($boolean);
Gets or sets whether supported checksums returned for downloaded
objects are verified.
The constructor default is true.
See ["CHECKSUMS"](#checksums).
## AUTHENTICATION AND CONFIGURATION METHODS
### get\_credentials
my ( $access_key_id, $secret_access_key, $token )
= $s3->get_credentials;
Returns the credentials used by the client.
When a `credentials` provider is configured, this method obtains the
three values from that provider.
Otherwise it returns the credentials stored by the `Amazon::S3`
object.
The return values, in order, are:
1. AWS access key ID.
2. AWS secret access key.
3. Session token, or `undef` when no token is configured.
See ["AUTHENTICATION AND CREDENTIALS"](#authentication-and-credentials).
### get\_default\_region
my $region = $s3->get_default_region;
Attempts to determine the default AWS region.
The method checks, in order:
1. `AWS_REGION`.
2. `AWS_DEFAULT_REGION`.
3. The EC2 instance metadata availability-zone endpoint.
When an availability zone is obtained from instance metadata, the
zone suffix is removed to derive the region.
If no region can be determined, `us-east-1` is returned.
### get\_logger
my $logger = $s3->get_logger;
Returns the logger associated with the client.
If no logger was supplied to `new()`, this is the
[Amazon::S3::Logger](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ALogger) instance created by the constructor.
This method is provided for compatibility with logger interfaces that
expect `get_logger()`.
See ["LOGGING AND DEBUGGING"](#logging-and-debugging).
### level
my $level = $s3->level;
$s3->level('debug');
Gets or sets the logging level.
When a level is supplied, both the stored logging level and the
associated logger level are updated.
When called without an argument, returns the current logger level.
The constructor default is `error`.
See ["LOGGING AND DEBUGGING"](#logging-and-debugging).
### region
my $region = $s3->region;
$s3->region('us-west-2');
Gets or sets the region used by the client.
The region is used for account-level requests and as the default
region assigned to bucket objects when no bucket-specific region is
supplied.
When the configured host uses the standard `s3.amazonaws.com` form,
setting the region also adjusts the host to the regional Amazon S3
endpoint.
The constructor default is `us-east-1`.
### signer
my $signer = $s3->signer;
Returns the Signature Version 4 signer used for requests.
If a signer was supplied to the constructor, that signer is returned.
Otherwise a signer is constructed from the current credentials,
region, and session token.
When `cache_signer` is true, a generated signer is retained and
reused. When it is false, a signer can be generated as needed.
This method does not accept a signer argument. Supply a custom signer
using the `signer` constructor option.
See ["AUTHENTICATION AND CREDENTIALS"](#authentication-and-credentials).
## BUCKET MANAGEMENT
### add\_bucket
my $bucket = $s3->add_bucket(\%configuration);
Creates a bucket.
The argument is a hash reference containing the bucket configuration.
- bucket
Required. Bucket name.
- acl\_short
Optional canned ACL.
Optional canned ACL applied when creating the bucket.
See ["WORKING WITH BUCKETS AND OBJECTS"](#working-with-buckets-and-objects).
share/README.md view on Meta::CPAN
The S3 default is 1000.
- prefix
Optional prefix used to restrict returned keys.
- version-id-marker
Optional version ID marker used with `key-marker` when continuing a
paginated listing.
On success, returns the parsed ListObjectVersions service response.
This method does not automatically follow pagination.
On failure, returns `undef` and records error information on the
client.
See ["LISTING OBJECTS"](#listing-objects) and
[https://docs.aws.amazon.com/AmazonS3/latest/API/API\_ListObjectVersions.html](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectVersions.html).
=head2 ADVANCED AND COMPATIBILITY METHODS
### turn\_off\_special\_retry
$s3->turn_off_special_retry;
Removes the additional HTTP 400 retry condition installed by
`turn_on_special_retry()`.
When retry handling is disabled, this method has no effect.
This method exists primarily for internal and compatibility use.
### turn\_on\_special\_retry
$s3->turn_on_special_retry;
When retry handling is enabled, adds HTTP 400 to the conditions
handled by the retry-aware user agent.
This behavior exists because some S3 request timeouts have historically
been returned as HTTP 400 responses.
The constructor calls this method automatically.
When retry handling is disabled, this method has no effect.
This method exists primarily for internal and compatibility use.
# LOGGING AND DEBUGGING
Logging is controlled by the configured logger and logging level.
When no logger is supplied, `Amazon::S3::Logger` is used.
Valid levels include:
fatal
error
warn
info
debug
trace
The default level is `error`.
At `debug` level, `Amazon::S3` records higher-level request and
configuration information.
At `trace` level, HTTP request and response information may also be
logged.
Applications should review trace output before retaining or sharing
it. Request and response data may contain sensitive application
information even when authentication values are sanitized.
# S3-COMPATIBLE SERVICES
`Amazon::S3` can be used with S3-compatible services and local S3
implementations by configuring the service endpoint and related
connection options.
The `host`, `secure`, and `dns_bucket_names` settings are commonly
relevant when using a non-AWS endpoint.
S3-compatible implementations may differ from AWS in supported APIs,
request validation, checksum behavior, or edge cases.
The integration tests used during development include LocalStack, but
applications targeting another S3-compatible implementation should
test against that implementation directly.
# COMPARISON TO OTHER PERL S3 MODULES
Perl applications have several choices for accessing Amazon S3,
including [Net::Amazon::S3](https://metacpan.org/pod/Net%3A%3AAmazon%3A%3AS3), [Paws::S3](https://metacpan.org/pod/Paws%3A%3AS3), [Amazon::S3::Lite](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ALite), and
[Amazon::API::S3](https://metacpan.org/pod/Amazon%3A%3AAPI%3A%3AS3). Each takes a different approach.
`Amazon::S3` provides a dedicated S3 interface with a long-established
API. The distribution combines the account-level `Amazon::S3`
interface with [Amazon::S3::Bucket](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ABucket) for common object workflows and
[Amazon::S3::BucketV2](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ABucketV2) for broader low-level API access.
`Net::Amazon::S3` is the project from which `Amazon::S3` originally
forked. The distributions have since diverged and should not be
considered drop-in replacements for one another.
`Paws::S3` is part of the larger [Paws](https://metacpan.org/pod/Paws) AWS SDK for Perl and follows
AWS service APIs through its generated service model.
[Amazon::S3::Lite](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ALite) is a smaller client intended for applications
where dependency size and startup cost are important.
[Amazon::API::S3](https://metacpan.org/pod/Amazon%3A%3AAPI%3A%3AS3) is generated from the AWS Botocore service model
and is intended to closely reflect the current low-level S3 API.
The appropriate client depends primarily on the interface and level of
abstraction required by the application.
# COMPATIBILITY AND LIMITATIONS
## Minimum Perl Version
`Amazon::S3` declares Perl 5.10 as its minimum supported Perl
version.
Dependencies may impose additional constraints on older Perl
installations.
Applications using an older Perl should run the complete distribution
test suite after installation.
## Signature Version 4
AWS API requests are signed using Signature Version 4.
Signature Version 2 is not supported.
Because Signature Version 4 includes the AWS region in the signature,
bucket operations must use the region containing the bucket.
A bucket region can be supplied explicitly or determined using bucket
region verification.
## Directory Buckets
Directory bucket support is currently limited to account-level create
and list operations.
See ["DIRECTORY BUCKETS"](#directory-buckets).
# TESTING
The distribution includes unit tests and integration tests that
exercise behavior requiring an S3 endpoint.
Run the normal distribution test suite with:
make test
Integration testing during development includes LocalStack.
See `README-TESTING.md` in the distribution root for test
environment setup, integration-test requirements, and additional
testing instructions.
# SUPPORT
Bug reports and feature requests should be submitted through the
project issue tracker.
When reporting a problem, include the `Amazon::S3` version, Perl
version, operating system, and enough information to reproduce the
behavior.
For request or protocol problems, debug or trace logging may also be
useful. Review logs before sharing them to ensure that they do not
contain credentials, authorization information, or sensitive object
data.
# REPOSITORY
The source repository, issue tracker, and development history are
available at:
[https://github.com/rlauer6/Amazon-S3](https://github.com/rlauer6/Amazon-S3)
# AUTHOR
Original author: Timothy Appnel <tima@cpan.org>
Current maintainer: Rob Lauer <bigfoot@cpan.org>
# SEE ALSO
[Amazon::S3::Bucket](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ABucket)
[Amazon::S3::BucketV2](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ABucketV2)
[Amazon::S3::Constants](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3AConstants)
[Amazon::S3::Logger](https://metacpan.org/pod/Amazon%3A%3AS3%3A%3ALogger)
[Amazon::Credentials](https://metacpan.org/pod/Amazon%3A%3ACredentials)
[Net::Amazon::S3](https://metacpan.org/pod/Net%3A%3AAmazon%3A%3AS3)
[Amazon S3 API Reference](https://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html)
[Amazon S3 bucket naming rules](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html)
[Amazon S3 bucket restrictions and limitations](https://docs.aws.amazon.com/AmazonS3/latest/userguide/BucketRestrictions.html)
[AWS Signature Version 4](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html)
[Amazon S3 directory buckets](https://docs.aws.amazon.com/AmazonS3/latest/userguide/directory-buckets-overview.html)
[LocalStack](https://localstack.io)
# LICENCE
This library is free software; you may redistribute it and/or modify
it under the same terms as Perl itself.
Portions of this distribution contain code modified from Amazon. That
code is made available under 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.
( run in 0.409 second using v1.01-cache-2.11-cpan-062aa07a564 )