AWS-Lambda-Quick

 view release on metacpan or  search on metacpan

INSTALL  view on Meta::CPAN


Installing AWS-Lambda-Quick is straightforward.

## Installation with cpanm

If you have cpanm, you only need one line:

    % cpanm AWS::Lambda::Quick

If it does not have permission to install modules to the current perl, cpanm
will automatically set up and install to a local::lib in your home directory.
See the local::lib documentation (https://metacpan.org/pod/local::lib) for
details on enabling it in your environment.

## Installing with the CPAN shell

Alternatively, if your CPAN shell is set up, you should just be able to do:

    % cpan AWS::Lambda::Quick

## Manual installation

As a last resort, you can manually install it. Download the tarball, untar it,
install configure prerequisites (see below), then build it:

    % perl Makefile.PL
    % make && make test

README.md  view on Meta::CPAN


    use AWS::Lambda::Quick (
        name => 'random-lottery-numbers',
    );

And then execute it locally.  Rather than running as normal your script
will instead upload itself to AWS as a Lambda function (modifying
itself so that it no longer has a dependency on AWS::Lambda::Quick) and
handle all the other steps needed to make itself web accessible.
Running the script locally subsequent times will update the code and
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

README.md  view on Meta::CPAN

resource (i.e. off of "/") and will be named after the name of the
Lambda function (i.e. calling `use AWS::Lambda::Quick (name =` "foo")>
will create a resource `/foo`)

### Create a new method

Each Lambda function we create gets its own method, which is where
AWS specifies what HTTP method it accepts (`GET`,`POST`,`PUT`,
etc.) and how it decides who can access it.

This module always sets the type of method to `ANY` (i.e. we always
call the lambda function and let it figure out what it wants to accept
or not.)

We setup the `NONE` authentication, meaning anyone can call the API
over the internet - i.e. it's configured as a public API.

### Create a new integration

Integrations are how AWS decides both where a request is routed to
and what extracted from that HTTP request is passed on and how.

We configure an AWS\_PROXY integration routing to our new Lambda
function.  This essentially means everything is passed "as is"
through to our handler as the first argument.

README.md  view on Meta::CPAN

    `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.

    Currently AWS Lamda supports up to four extra layers (five in total
    including the prebuilt public layer for Perl.)  All layers, when
    decompressed, must be less that 250MB in size.

README.md  view on Meta::CPAN

Installing the tools are covered in many AWS guides, but can be
quickly summarized as:

    shell$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
    shell$ unzip awscli-bundle.zip
    shell$ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

You'll need to configure awscli with your own personal AWS Access
Key ID and AWS Secret Access Key.  You can create these from the AWS
Management console by following the guide on
[How to quickly find and update your access keys, password, and MFA setting using the AWS Management Console](https://aws.amazon.com/blogs/security/how-to-find-update-access-keys-password-mfa-aws-management-console/)

Once you have your keys you can then use the `configure` command
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

In the interest of being as quick as possible, when this is environment
variable is enabled the URL for the upload is not computed and printed
out.

## Enabling debugging output

To gain a little more insight into what is going on you can set
the `AWS_LAMBDA_QUICK_DEBUG` environment variable to enabled
debugging to STDERR:

    shell$ AWS_LAMBDA_QUICK_DEBUG=1 perl lambda-function.pl
    updating function code
    function code updated
    updating function configuration
    searching for existing role
    found existing role
    ...

lib/AWS/Lambda/Quick.pm  view on Meta::CPAN


    use AWS::Lambda::Quick (
        name => 'random-lottery-numbers',
    );

And then execute it locally.  Rather than running as normal your script
will instead upload itself to AWS as a Lambda function (modifying
itself so that it no longer has a dependency on AWS::Lambda::Quick) and
handle all the other steps needed to make itself web accessible.
Running the script locally subsequent times will update the code and
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

lib/AWS/Lambda/Quick.pm  view on Meta::CPAN

resource (i.e. off of "/") and will be named after the name of the
Lambda function (i.e. calling C<use AWS::Lambda::Quick (name => "foo")>
will create a resource C</foo>)

=head3 Create a new method

Each Lambda function we create gets its own method, which is where
AWS specifies what HTTP method it accepts (C<GET>,C<POST>,C<PUT>,
etc.) and how it decides who can access it.

This module always sets the type of method to C<ANY> (i.e. we always
call the lambda function and let it figure out what it wants to accept
or not.)

We setup the C<NONE> authentication, meaning anyone can call the API
over the internet - i.e. it's configured as a public API.

=head3 Create a new integration

Integrations are how AWS decides both where a request is routed to
and what extracted from that HTTP request is passed on and how.

We configure an AWS_PROXY integration routing to our new Lambda
function.  This essentially means everything is passed "as is"
through to our handler as the first argument.

lib/AWS/Lambda/Quick.pm  view on Meta::CPAN

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.

Currently AWS Lamda supports up to four extra layers (five in total
including the prebuilt public layer for Perl.)  All layers, when
decompressed, must be less that 250MB in size.

lib/AWS/Lambda/Quick.pm  view on Meta::CPAN

Installing the tools are covered in many AWS guides, but can be
quickly summarized as:

    shell$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
    shell$ unzip awscli-bundle.zip
    shell$ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

You'll need to configure awscli with your own personal AWS Access
Key ID and AWS Secret Access Key.  You can create these from the AWS
Management console by following the guide on
L<How to quickly find and update your access keys, password, and MFA setting using the AWS Management Console|https://aws.amazon.com/blogs/security/how-to-find-update-access-keys-password-mfa-aws-management-console/>

Once you have your keys you can then use the C<configure> command
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

In the interest of being as quick as possible, when this is environment
variable is enabled the URL for the upload is not computed and printed
out.

=head2 Enabling debugging output

To gain a little more insight into what is going on you can set
the C<AWS_LAMBDA_QUICK_DEBUG> environment variable to enabled
debugging to STDERR:

    shell$ AWS_LAMBDA_QUICK_DEBUG=1 perl lambda-function.pl
    updating function code
    function code updated
    updating function configuration
    searching for existing role
    found existing role
    ...

perlcriticrc  view on Meta::CPAN

[CodeLayout::RequireTrailingCommas]
severity = 3

[ControlStructures::ProhibitCStyleForLoops]
severity = 3

[Documentation::RequirePackageMatchesPodName]
severity = 3

[Freenode::WhileDiamondDefaultAssignment]
set_themes = core

[InputOutput::RequireCheckedSyscalls]
functions = :builtins
exclude_functions = sleep
severity = 3

[Moose::RequireCleanNamespace]
modules = Moose Moose::Role MooseX::Role::Parameterized Moose::Util::TypeConstraints
cleaners = namespace::autoclean



( run in 1.483 second using v1.01-cache-2.11-cpan-49f99fa48dc )