AWS-Lambda-Quick
view release on metacpan or search on metacpan
lib/AWS/Lambda/Quick/Upload.pm view on Meta::CPAN
package AWS::Lambda::Quick::Upload;
use Mo qw( default required );
our $VERSION = '1.0002';
use AWS::CLIWrapper;
use JSON::PP ();
### required attributes
has zip_filename => required => 1;
has name => required => 1;
### optional attributes wrt the lambda function itself
has extra_layers => default => [];
has region => default => 'us-east-1';
has memory_size => default => 128; # this is the AWS default
has timeout => default => 3; # this is the AWS default
has description => default => 'A Perl AWS::Lambda::Quick Lambda function.';
has stage_name => default => 'quick';
### lambda function computed attributes
has aws => sub {
my $self = shift;
return AWS::CLIWrapper->new(
region => $self->region,
);
};
has zip_file_blob => sub { 'fileb://' . shift->zip_filename };
# should we create the function from scratch or just update it?
# by default we interogate the api to see if it exists already
has update_type => sub {
my $self = shift;
my $aws = $self->aws;
my $result = $aws->lambda(
'get-function',
{
'function-name' => $self->name,
}
);
return $result ? 'update-function' : 'create-function';
};
### role attributes
has role => default => 'perl-aws-lambda-quick';
has _role_arn => sub {
my $self = shift;
# if whatever we were passed in role was an actual ARN then we
# can just use that without any further lookups
if ( $self->role
=~ /^arn:(aws[a-zA-Z-]*)?:iam::\d{12}:role\/?[a-zA-Z_0-9+=,.@\-_\/]+$/
) {
$self->debug('using passed role arn');
return $self->role;
}
$self->debug('searching for existing role');
my $aws = $self->aws;
my $result = $aws->iam(
'get-role',
{
'role-name' => $self->role,
}
( run in 1.049 second using v1.01-cache-2.11-cpan-f56aa216473 )