AnyEvent-EC2-Tiny
view release on metacpan or search on metacpan
NAME
AnyEvent::EC2::Tiny - Tiny asynchronous (non-blocking) interface to EC2
using AnyEvent
VERSION
version 0.002
SYNOPSIS
use v5.14;
use AnyEvent::EC2::Tiny;
my $ec2 = AnyEvent::EC2::Tiny->new(
AWSAccessKey => $ENV{'AWS_ACCESS_KEY'},
AWSSecretKey => $ENV{'AWS_SECRET_KEY'},
region => $ENV{'AWS_REGION'},
debug => 1,
);
# We are essentially encoding 'raw' EC2 API calls with a v2
# signature and turning XML responses into Perl data structures
my $xml = $ec2->send(
'RegionName.1' => 'us-east-1',
Action => 'DescribeRegions',
success_cb => sub {
my $xml = shift;
# prints ec2.us-east-1.amazonaws.com
say $xml->{'regionInfo'}{'item'}[0]{'regionEndpoint'};
},
fail_cb => sub {
my $error = shift;
$error->{'type'} # HTTP or XML
$error->{'data'} # hashref to body, errors, xml, headers, etc.
$error->{'text'} # text of the error
},
);
DESCRIPTION
This is a basic asynchronous, non-blocking, interface to EC2 based on
Net::EC2::Tiny. It's relatively compatible while the only difference is
with regards to the callbacks and returned information.
METHODS
send
"send()" expects the same arguments as "send()" in Net::EC2::Tiny,
except you should also provide two additional arguments.
success_cb
$ec2->send(
...
success_cb => sub {
my $xml = shift;
# do whatever you want with it
},
);
Receives the resulting XML you would normally receive. Then you do
whatever you want with it, such as fetching the information or using it
to create another request.
fail_cb
$ec2->send(
...
fail_cb => sub {
my $error = shift;
if ( $error->{'type'} eq 'HTTP' ) {
# this was an HTTP error
my $http_headers = $error->{'data'}{'headers'};
my $http_body = $error->{'data'}{'body'};
warn 'HTTP error received: ', $error->{'text'};
} else {
# $error->{'type'} eq 'XML'
( run in 1.050 second using v1.01-cache-2.11-cpan-39bf76dae61 )