AWS-CLIWrapper
view release on metacpan or search on metacpan
lib/AWS/CLIWrapper.pm view on Meta::CPAN
use JSON 2;
use IPC::Cmd;
use String::ShellQuote;
use Carp;
our $Error = { Message => '', Code => '' };
our $true = do { bless \(my $dummy = 1), "AWS::CLIWrapper::Boolean" };
our $false = do { bless \(my $dummy = 0), "AWS::CLIWrapper::Boolean" };
my $AWSCLI_VERSION = undef;
my $DEFAULT_CATCH_ERROR_RETRIES = 3;
my $DEFAULT_CATCH_ERROR_MIN_DELAY = 3;
my $DEFAULT_CATCH_ERROR_MAX_DELAY = 10;
sub new {
my($class, %param) = @_;
my $region = $param{region};
my @opt = ();
lib/AWS/CLIWrapper.pm view on Meta::CPAN
croak_on_error => Int (>0)
When set to a truthy value, this will make AWS::CLIWrapper to croak() with error message when `aws` command exits with non-zero status. Default behavior is to set $AWS::CLIWrapper::Error and return.
catch_error_pattern => RegExp
When defined, this option will enable catching `aws-cli` errors matching this pattern
and retrying `aws-cli` command execution. Environment variable
AWS_CLIWRAPPER_CATCH_ERROR_PATTERN takes precedence over this option, if both
are defined.
Default is undef.
catch_error_retries => Int (>= 0)
When defined, this option will set the number of retries to make when `aws-cli` error
was caught with catch_error_pattern, before giving up. Environment variable
AWS_CLIWRAPPER_CATCH_ERROR_RETRIES takes precedence over this option, if both
are defined.
0 (zero) retries is a valid way to turn off error catching via environment variable
in certain scenarios. Negative values are invalid and will be reset to default.
t/03_awscli_timeout.t view on Meta::CPAN
use strict;
use Test::More;
use AWS::CLIWrapper;
{
local $ENV{AWS_CLIWRAPPER_TIMEOUT} = undef;
my $aws = AWS::CLIWrapper->new();
is $aws->{timeout}, 30, "default timeout is 30 seconds";
}
{
local $ENV{AWS_CLIWRAPPER_TIMEOUT} = 3600;
my $aws = AWS::CLIWrapper->new();
t/04_errors.t view on Meta::CPAN
# Default error handling
my $aws = AWS::CLIWrapper->new;
if ($aws->awscli_version == 0) {
plan skip_all => 'not found aws command';
} else {
plan tests => 4;
}
my $res = $aws->elbv2();
is $res, undef, "default result is undefined";
# Is this a TODO?
is $AWS::CLIWrapper::Error->{Code}, "Unknown", "default error code match";
my $want_err_msg = qr!exited with code \[\d+\]
stderr:
.*
usage: aws \[options\] <command> <subcommand> \[<subcommand> ...\] \[parameters\]
To see help text, you can run:
t/05_catch_error_options.t view on Meta::CPAN
__DATA__
# line 41
{
'mock-aws version' => {
method => 'awscli_version',
want => '2.42.4242',
},
'default-catch_error_pattern' => {
method => 'catch_error_pattern',
want => undef,
},
'default-catch_error_retries' => {
method => 'catch_error_retries',
want => 3,
},
'default-catch_error_min_delay' => {
method => 'catch_error_min_delay',
want => 3,
},
'default-catch_error_max_delay' => {
t/06_catch_errors.t view on Meta::CPAN
}
done_testing;
__DATA__
# line 60
{
'no-error' => {
command => 'ecs',
subcommand => 'list-clusters',
error_to_die_with => undef,
error_msg_re => qr{^$},
exception => qr{^$},
want => {
clusterArns => [
"arn:aws:ecs:us-foo-1:123456789:cluster/foo",
"arn:aws:ecs:us-foo-1:123456789:cluster/bar",
"arn:aws:ecs:us-foo-1:123456789:cluster/baz"
],
}
},
'no-croak' => {
command => 'ecs',
subcommand => 'list-clusters',
error_to_die_with => 'uh-oh',
error_msg_re => qr{uh-oh},
exception => qr{^$},
want => undef,
},
'with-croak' => {
wrapper_args => { croak_on_error => 1 },
command => 'ecs',
subcommand => 'list-clusters',
error_to_die_with => 'foobaroo!',
error_msg_re => qr{foobaroo},
exception => qr{foobaroo},
want => undef,
},
'catch-no-croak' => {
env => {
AWS_CLIWRAPPER_CATCH_ERROR_PATTERN => 'FUBAR',
AWS_CLIWRAPPER_CATCH_ERROR_MIN_DELAY => 0,
AWS_CLIWRAPPER_CATCH_ERROR_MAX_DELAY => 0,
},
command => 'ecs',
subcommand => 'list-clusters',
error_to_die_with => 'FUBAR',
( run in 1.457 second using v1.01-cache-2.11-cpan-d80b1682f3f )