AWS-Lambda-Quick
view release on metacpan or search on metacpan
"version" : 1.0002,
"x_Dist_Zilla" : {
"perl" : {
"version" : "5.028001"
},
"plugins" : [
{
"class" : "Dist::Zilla::Plugin::MakeMaker",
"config" : {
"Dist::Zilla::Role::TestRunner" : {
"default_jobs" : 1
}
},
"name" : "@MAXMIND/MakeMaker",
"version" : "6.012"
},
{
"class" : "Dist::Zilla::Plugin::Git::GatherDir",
"config" : {
"Dist::Zilla::Plugin::GatherDir" : {
"exclude_filename" : [
},
{
"class" : "Dist::Zilla::Plugin::PodSyntaxTests",
"name" : "@MAXMIND/PodSyntaxTests",
"version" : "6.012"
},
{
"class" : "Dist::Zilla::Plugin::RunExtraTests",
"config" : {
"Dist::Zilla::Role::TestRunner" : {
"default_jobs" : 1
}
},
"name" : "@MAXMIND/RunExtraTests",
"version" : "0.029"
},
{
"class" : "Dist::Zilla::Plugin::MojibakeTests",
"name" : "@MAXMIND/MojibakeTests",
"version" : "0.8"
},
repository: git://github.com/2shortplanks/aws-lambda-quick.git
version: '1.0002'
x_Dist_Zilla:
perl:
version: '5.028001'
plugins:
-
class: Dist::Zilla::Plugin::MakeMaker
config:
Dist::Zilla::Role::TestRunner:
default_jobs: 1
name: '@MAXMIND/MakeMaker'
version: '6.012'
-
class: Dist::Zilla::Plugin::Git::GatherDir
config:
Dist::Zilla::Plugin::GatherDir:
exclude_filename:
- CONTRIBUTING.md
- LICENSE
- Makefile.PL
name: '@MAXMIND/Test::PodSpelling'
version: '2.007005'
-
class: Dist::Zilla::Plugin::PodSyntaxTests
name: '@MAXMIND/PodSyntaxTests'
version: '6.012'
-
class: Dist::Zilla::Plugin::RunExtraTests
config:
Dist::Zilla::Role::TestRunner:
default_jobs: 1
name: '@MAXMIND/RunExtraTests'
version: '0.029'
-
class: Dist::Zilla::Plugin::MojibakeTests
name: '@MAXMIND/MojibakeTests'
version: '0.8'
-
class: Dist::Zilla::Plugin::Test::CPAN::Changes
config:
Dist::Zilla::Plugin::Test::CPAN::Changes:
AWS settings.
## What This Actually Does
You probably don't care about this, but this is actually what's
going on when the script uploads itself. This is subject to change
in later versions of this utility as better ways to do things
become available (for example AWS has a HTTP API that is currently in
beta that could make some of this easier!).
By default, unless you specify extra parameters when you import
AWS::Lambda::Quick, AWS will be configured as described below
### Create A New Role For Use With AWS::Lambda::Quick
Execution creates a new role called `perl-aws-lambda-quick` that can
be assumed by both the API Gateway (`apigateway.amazonaws.com`) and
Lambda (`lambda.amazonaws.com`) services. The role will have
`AWSLambdaRole` and `CloudWatchLogsFullAccess` policies permissioned
(so it execute the lambda function and write logs.)
Lambda, they get Lambda data back to HTTP.
Because we want our handler to have complete control over the output
we don't do anything special with what we create.
### Deploying the Code.
Once all the above is done the module finally deploys the code
so it's web accessible.
By default this is to the `quick`, though you can reconfigure that
with the `stage_name` parameter.
## Parameters
This is a full list of parameters you can currently configure. Only
one parameter - `name` - is required and all other parameters are
optional and will have hopefully sensible defaults.
It is not the intent of the author to provide a complete and exhaustive
list of all possibilities - you have the power of the AWS Management
console and AWS API to make any further tweaks you may desire.
- name
The name of the Lambda function. Required.
This will become part of the URL that can be used to call this
);
These filenames must be relative and will be expected to be in the
same directory as the script itself. Passing a directory name will
cause the directory contents to be recursively uploaded. If a named
file/directory is not present at the passed location it will be
silently ignored.
- region
The region you wish to deploy the lamda function to. By default
this will be `us-east-1`.
- memory\_size
The amount of memory that your function has access to. Increasing
the function's memory also increases its CPU allocation. The default
value is 128 MB. The value must be a multiple of 64 MB.
- timeout
The amount of time that Lambda allows a function to run before stopping
it. The default is 3 seconds. The maximum allowed value is 900 seconds.
- role
The AWS role you want to run the Lambda function as. This can
either be a full arn, or the name of the role to use (which will
be automatically created with permissions to run Lambda functions
if it does not exist).
If you do not pass a role argument the role with the name
`perl-aws-lambda-quick` will be used (and created if it does not
The id of the rest api to use. If no id is passed then it is
automatically determined from the rest\_api parameter.
Including this value will make your script less portable between
accounts, but will reduce the number of API calls made during updates.
- rest\_api
The name of the rest api to use if you did not pass a `rest_api_id`
(if you did this parameter will be ignored.) Will default to
`perl-aws-lambda-quick` if not passed. If no such named rest api
exists then one will be automatically created.
- stage\_name
The name we stage to. By default this is `quick` meaning that
our live URL will be of the form:
https://????.execute-api.????.amazonaws.com/quick/????
By setting stage\_name to another value you can change this.
- extra\_layers
An arrayref of extra layers (in addition to the standard prebuilt public
Lambda layer for Perl) that will be used by this Lambda function.
to update the aws command line utility.
shell$ aws configure
AWS Access Key ID [********************]:
AWS Secret Access Key [********************]:
Default region name [us-east-1]:
Default output format [None]:
## Speeding up Code Updates
By default this module will check that everything is configured
correctly in AWS and will make changes as needed. This requires several
API calls (and several executions of the AWS python command line
tool.)
If you've only changed the source code and want to deploy a new version
you can just do that by setting the `AWS_LAMBDA_QUICK_UPDATE_CODE_ONLY`
enviroment variable:
shell$ AWS_LAMBDA_QUICK_UPDATE_CODE_ONLY=1 perl lambda-function.pl
lib/AWS/Lambda/Quick.pm view on Meta::CPAN
AWS settings.
=head2 What This Actually Does
You probably don't care about this, but this is actually what's
going on when the script uploads itself. This is subject to change
in later versions of this utility as better ways to do things
become available (for example AWS has a HTTP API that is currently in
beta that could make some of this easier!).
By default, unless you specify extra parameters when you import
AWS::Lambda::Quick, AWS will be configured as described below
=head3 Create A New Role For Use With AWS::Lambda::Quick
Execution creates a new role called C<perl-aws-lambda-quick> that can
be assumed by both the API Gateway (C<apigateway.amazonaws.com>) and
Lambda (C<lambda.amazonaws.com>) services. The role will have
C<AWSLambdaRole> and C<CloudWatchLogsFullAccess> policies permissioned
(so it execute the lambda function and write logs.)
lib/AWS/Lambda/Quick.pm view on Meta::CPAN
Lambda, they get Lambda data back to HTTP.
Because we want our handler to have complete control over the output
we don't do anything special with what we create.
=head3 Deploying the Code.
Once all the above is done the module finally deploys the code
so it's web accessible.
By default this is to the C<quick>, though you can reconfigure that
with the C<stage_name> parameter.
=head2 Parameters
This is a full list of parameters you can currently configure. Only
one parameter - C<name> - is required and all other parameters are
optional and will have hopefully sensible defaults.
It is not the intent of the author to provide a complete and exhaustive
list of all possibilities - you have the power of the AWS Management
console and AWS API to make any further tweaks you may desire.
=over
=item name
The name of the Lambda function. Required.
lib/AWS/Lambda/Quick.pm view on Meta::CPAN
);
These filenames must be relative and will be expected to be in the
same directory as the script itself. Passing a directory name will
cause the directory contents to be recursively uploaded. If a named
file/directory is not present at the passed location it will be
silently ignored.
=item region
The region you wish to deploy the lamda function to. By default
this will be C<us-east-1>.
=item memory_size
The amount of memory that your function has access to. Increasing
the function's memory also increases its CPU allocation. The default
value is 128 MB. The value must be a multiple of 64 MB.
=item timeout
The amount of time that Lambda allows a function to run before stopping
it. The default is 3 seconds. The maximum allowed value is 900 seconds.
=item role
The AWS role you want to run the Lambda function as. This can
either be a full arn, or the name of the role to use (which will
be automatically created with permissions to run Lambda functions
if it does not exist).
If you do not pass a role argument the role with the name
C<perl-aws-lambda-quick> will be used (and created if it does not
lib/AWS/Lambda/Quick.pm view on Meta::CPAN
The id of the rest api to use. If no id is passed then it is
automatically determined from the rest_api parameter.
Including this value will make your script less portable between
accounts, but will reduce the number of API calls made during updates.
=item rest_api
The name of the rest api to use if you did not pass a C<rest_api_id>
(if you did this parameter will be ignored.) Will default to
C<perl-aws-lambda-quick> if not passed. If no such named rest api
exists then one will be automatically created.
=item stage_name
The name we stage to. By default this is C<quick> meaning that
our live URL will be of the form:
https://????.execute-api.????.amazonaws.com/quick/????
By setting stage_name to another value you can change this.
=item extra_layers
An arrayref of extra layers (in addition to the standard prebuilt public
Lambda layer for Perl) that will be used by this Lambda function.
lib/AWS/Lambda/Quick.pm view on Meta::CPAN
to update the aws command line utility.
shell$ aws configure
AWS Access Key ID [********************]:
AWS Secret Access Key [********************]:
Default region name [us-east-1]:
Default output format [None]:
=head2 Speeding up Code Updates
By default this module will check that everything is configured
correctly in AWS and will make changes as needed. This requires several
API calls (and several executions of the AWS python command line
tool.)
If you've only changed the source code and want to deploy a new version
you can just do that by setting the C<AWS_LAMBDA_QUICK_UPDATE_CODE_ONLY>
enviroment variable:
shell$ AWS_LAMBDA_QUICK_UPDATE_CODE_ONLY=1 perl lambda-function.pl
lib/AWS/Lambda/Quick/CreateZip.pm view on Meta::CPAN
package AWS::Lambda::Quick::CreateZip;
use Mo qw( default required );
our $VERSION = '1.0002';
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Path::Tiny qw( path );
has src_filename => required => 1;
has zip_filename => required => 1;
has extra_files => default => [];
has _src_path => sub { path( shift->src_filename ) };
has _src_dir => sub { shift->_src_path->parent };
has _zip_class => default => 'Archive::Zip';
has _zip => sub { shift->_zip_class->new };
has _script_src => sub { shift->_src_path->slurp_raw };
# this is the same src as in script src but the first occurance of
# "use AWS::Lambda::Quick" is prepended with
# "$INC{'AWS/Lambda/Quick.pm'}=1" to prevent it actually being loaded
# from disk. Note this happens on just one line to avoid screwing
# with line numebrs that could mess with error messages
has _converted_src => sub {
my $self = shift;
lib/AWS/Lambda/Quick/Processor.pm view on Meta::CPAN
package AWS::Lambda::Quick::Processor;
use Mo qw( default required );
our $VERSION = '1.0002';
use AWS::Lambda::Quick::CreateZip ();
use AWS::Lambda::Quick::Upload ();
use File::Temp qw( tempdir );
use Path::Tiny qw( path );
has name => required => 1;
has src_filename => required => 1;
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;
lib/AWS/Lambda/Quick/Upload.pm view on Meta::CPAN
'arn:aws:iam::aws:policy/CloudWatchLogsFullAccess',
'role-name' => $self->role,
}
);
$self->debug('permissions attached to role');
return $result->{Role}{Arn};
};
### rest api attributes
has rest_api => default => 'perl-aws-lambda-quick';
has rest_api_id => sub {
my $self = shift;
# search existing apis
$self->debug('searching for existing rest api');
my $result = $self->aws_do(
'apigateway',
'get-rest-apis',
);
for ( @{ $result->{items} } ) {
( run in 0.517 second using v1.01-cache-2.11-cpan-0a6323c29d9 )