AWS-Lambda-Quick

 view release on metacpan or  search on metacpan

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


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.

This will become part of the URL that can be used to call this
function so you are strongly encouraged not to use any non-url
safe characters (including C</>, C<?>, etc) in the name.

=item description

The description of the Lambda function (shown in the AWS console, etc.)

=item extra_files

An array of extra files and directories that you wish to upload in
addition to the script itself.

For example, to upload the C<lib> directory, you would write:

    use AWS::Lambda::Quick (
        name => 'some-script-that-needs-modules',
        extra_files => [ 'lib' ],
    );

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
exist).

=item rest_api_id

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.

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.

You may either identify a layer by its ARN, or by using a identifying
name that is known to this module.  At this time the only known
identifying name is C<paws> which indicates that the Lambda function
should use the prebuilt Paws layer in the same region as the Lambda
function.

    use AWS::Lambda::Quick (
        name => 'email sender',
        extra_layers => [ 'paws' ],
    );

=back

=head2 Installing the CLI tools

This module requires you to have the version 1 AWS CLI tools installed
on your system and configured with your authentication credentials.
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
    ...

=head1 AUTHOR

Written by Mark Fowler B<mark@twoshortplanks.com>

Copyright Mark Fowler 2019.

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 SEE ALSO

L<AWS::Lambda>, L<AWS::CLIWrapper>

=cut



( run in 1.683 second using v1.01-cache-2.11-cpan-39bf76dae61 )