AWS-Lambda-Quick
view release on metacpan or search on metacpan
}
],
"include_underscores" : 0
},
"Dist::Zilla::Role::MetaProvider::Provider" : {
"$Dist::Zilla::Role::MetaProvider::Provider::VERSION" : "2.002004",
"inherit_missing" : 1,
"inherit_version" : 1,
"meta_noindex" : 1
},
"Dist::Zilla::Role::ModuleMetadata" : {
"Module::Metadata" : "1.000033",
"version" : "0.006"
}
},
"name" : "@MAXMIND/MetaProvides::Package",
"version" : "2.004003"
},
{
"class" : "Dist::Zilla::Plugin::Meta::Contributors",
"name" : "@MAXMIND/Meta::Contributors",
"version" : "0.003"
"repo_root" : ".",
"version" : "0.009"
}
},
"name" : "@MAXMIND/Generate CONTRIBUTING.md",
"version" : "0.014"
},
{
"class" : "Dist::Zilla::Plugin::InstallGuide",
"config" : {
"Dist::Zilla::Role::ModuleMetadata" : {
"Module::Metadata" : "1.000033",
"version" : "0.006"
}
},
"name" : "@MAXMIND/InstallGuide",
"version" : "1.200013"
},
{
"class" : "Dist::Zilla::Plugin::CPANFile",
"name" : "@MAXMIND/CPANFile",
"version" : "6.012"
"version" : "0.001"
},
{
"class" : "Dist::Zilla::Plugin::CheckSelfDependency",
"config" : {
"Dist::Zilla::Plugin::CheckSelfDependency" : {
"finder" : [
":InstallModules"
]
},
"Dist::Zilla::Role::ModuleMetadata" : {
"Module::Metadata" : "1.000033",
"version" : "0.006"
}
},
"name" : "@MAXMIND/CheckSelfDependency",
"version" : "0.011"
},
{
"class" : "Dist::Zilla::Plugin::CheckPrereqsIndexed",
"name" : "@MAXMIND/CheckPrereqsIndexed",
"version" : "0.020"
-
class: Dist::Zilla::Plugin::FinderCode
name: '@MAXMIND/MetaProvides::Package/AUTOVIV/:InstallModulesPM'
version: '6.012'
include_underscores: 0
Dist::Zilla::Role::MetaProvider::Provider:
$Dist::Zilla::Role::MetaProvider::Provider::VERSION: '2.002004'
inherit_missing: '1'
inherit_version: '1'
meta_noindex: '1'
Dist::Zilla::Role::ModuleMetadata:
Module::Metadata: '1.000033'
version: '0.006'
name: '@MAXMIND/MetaProvides::Package'
version: '2.004003'
-
class: Dist::Zilla::Plugin::Meta::Contributors
name: '@MAXMIND/Meta::Contributors'
version: '0.003'
-
class: Dist::Zilla::Plugin::MetaConfig
name: '@MAXMIND/MetaConfig'
source_filename: CONTRIBUTING.md
Dist::Zilla::Role::RepoFileInjector:
allow_overwrite: 1
repo_root: .
version: '0.009'
name: '@MAXMIND/Generate CONTRIBUTING.md'
version: '0.014'
-
class: Dist::Zilla::Plugin::InstallGuide
config:
Dist::Zilla::Role::ModuleMetadata:
Module::Metadata: '1.000033'
version: '0.006'
name: '@MAXMIND/InstallGuide'
version: '1.200013'
-
class: Dist::Zilla::Plugin::CPANFile
name: '@MAXMIND/CPANFile'
version: '6.012'
-
class: Dist::Zilla::Plugin::MAXMIND::License
name: '@MAXMIND/MAXMIND::License'
-
class: Dist::Zilla::Plugin::CheckStrictVersion
name: '@MAXMIND/CheckStrictVersion'
version: '0.001'
-
class: Dist::Zilla::Plugin::CheckSelfDependency
config:
Dist::Zilla::Plugin::CheckSelfDependency:
finder:
- ':InstallModules'
Dist::Zilla::Role::ModuleMetadata:
Module::Metadata: '1.000033'
version: '0.006'
name: '@MAXMIND/CheckSelfDependency'
version: '0.011'
-
class: Dist::Zilla::Plugin::CheckPrereqsIndexed
name: '@MAXMIND/CheckPrereqsIndexed'
version: '0.020'
-
class: Dist::Zilla::Plugin::MAXMIND::CheckChangesHasContent
name: '@MAXMIND/MAXMIND::CheckChangesHasContent'
#!/usr/bin/perl
use strict;
use warnings;
use AWS::Lambda::Quick (
name => 'hello-world',
);
sub handler {
my $data = shift;
my $name = $data->{queryStringParameters}{who} // "World";
return {
statusCode => 200,
headers => {
'Content-Type' => 'text/plain',
},
body => "Hello, $name",
};
}
1;
shell$ curl https://52p3rf890b.execute-api.us-east-1.amazonaws.com/quick/hello-world?who=Mark'
Hello, Mark
# DESCRIPTION
This module allows you to very quickly create a Perl based AWS
Lambda function which can be accessed via HTTP.
Coding Lambda functions in Perl is straight forward: You need only
implement a script with the one `handler` function that returns the
expected data structure as described in the [AWS::Lambda](https://metacpan.org/pod/AWS%3A%3ALambda)
documentation.
The hard part is configuring AWS to execute the code. Traditionally
you have to complete the following steps.
- Create a zip file containing your code
- Create (or update) an AWS Lambda function with this zip file
- Create a REST API with AWS Gateway API
- Configure a resource for that REST API for this script
- Set up a method and put method response for that resource
use strict;
use warnings;
use JSON::PP;
use AWS::Lambda::Quick (
name => 'echo',
);
sub handler {
my $data = shift;
return {
statusCode => 200,
headers => {
'Content-Type' => 'application/json',
},
body => encode_json($data),
};
}
1;
### Create a new integration-response and method-response
The integration response and method response are analogous to the
integration and method - but instead of getting data from HTTP to
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
lib/AWS/Lambda/Quick.pm view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use AWS::Lambda::Quick (
name => 'hello-world',
);
sub handler {
my $data = shift;
my $name = $data->{queryStringParameters}{who} // "World";
return {
statusCode => 200,
headers => {
'Content-Type' => 'text/plain',
},
body => "Hello, $name",
};
}
1;
lib/AWS/Lambda/Quick.pm view on Meta::CPAN
shell$ curl https://52p3rf890b.execute-api.us-east-1.amazonaws.com/quick/hello-world?who=Mark'
Hello, Mark
=head1 DESCRIPTION
This module allows you to very quickly create a Perl based AWS
Lambda function which can be accessed via HTTP.
Coding Lambda functions in Perl is straight forward: You need only
implement a script with the one C<handler> function that returns the
expected data structure as described in the L<AWS::Lambda>
documentation.
The hard part is configuring AWS to execute the code. Traditionally
you have to complete the following steps.
=over
=item Create a zip file containing your code
=item Create (or update) an AWS Lambda function with this zip file
lib/AWS/Lambda/Quick.pm view on Meta::CPAN
use strict;
use warnings;
use JSON::PP;
use AWS::Lambda::Quick (
name => 'echo',
);
sub handler {
my $data = shift;
return {
statusCode => 200,
headers => {
'Content-Type' => 'application/json',
},
body => encode_json($data),
};
}
1;
=head3 Create a new integration-response and method-response
The integration response and method response are analogous to the
integration and method - but instead of getting data from HTTP to
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
t/00-report-prereqs.t view on Meta::CPAN
# Add dynamic prereqs to the included modules list (if we can)
my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
my $cpan_meta_error;
if ( $source && $HAS_CPAN_META
&& (my $meta = eval { CPAN::Meta->load_file($source) } )
) {
$full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs);
}
else {
$cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source)
$source = 'static metadata';
}
my @full_reports;
my @dep_errors;
my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs;
# Add static includes into a fake section
for my $mod (@include) {
$req_hash->{other}{modules}{$mod} = 0;
}
BEGIN{$INC{'AWS/Lambda/Quick.pm'}=1} use AWS::Lambda::Quick (
name => 'whatever',
extra_files => 'lib',
);
use lib qw(lib);
use Greeting;
use JSON::PP qw( encode_json );
sub handler {
my $data = shift;
return {
statusCode => 200,
headers => {
'Content-Type' => 'text/plain',
},
body => Greeting->greeting( $data->{queryStringParameters}{who} ),
};
}
1;
PERL
is( $z->contents('lib/Greeting.pm'), <<'PERL', 'Greeting.pm was stored ok' );
package Greeting;
sub greeting {
my $class = shift;
my $name = shift;
t/lib/TestHelper/CreateTestFiles.pm view on Meta::CPAN
use AWS::Lambda::Quick (
name => 'whatever',
extra_files => 'lib',
);
use lib qw(lib);
use Greeting;
use JSON::PP qw( encode_json );
sub handler {
my $data = shift;
return {
statusCode => 200,
headers => {
'Content-Type' => 'text/plain',
},
body => Greeting->greeting( $data->{queryStringParameters}{who} ),
};
}
1;
PERL
# an example library
path( $dir, 'lib' )->mkpath;
path( $dir, 'lib', 'Greeting.pm' )->spew(<<'PERL');
package Greeting;
sub greeting {
( run in 0.360 second using v1.01-cache-2.11-cpan-8d75d55dd25 )