view release on metacpan or search on metacpan
105106107108109110111112113114115116117118119120121122123124125
- Europe (Stockholm) eu-north-1 is available
0.0.30 2021-10-06T00:13:52Z
- add amd64 compatible layers
- pre-install some modules
0.0.29 2021-07-16T11:25:47Z
- bump Paws 0.44
0.0.28 2021-06-13T15:46:13Z
- Fix mojibake
when
the input and the output are utf8 encoded
- Update WwwCounter v4.0.0 in the examples
0.0.27 2021-05-21T03:58:38Z
- Perl 5.34.0 is released
0.0.26 2021-05-09T02:54:24Z
- bump Paws 0.43
0.0.25 2021-03-02T05:32:05Z
- new region Asia Pacific (Osaka) ap-northeast-3 is available
161162163164165166167168169170171172173174175176177178179180181- [Mozilla::CA](https://metacpan.org/pod/Mozilla%3A%3ACA)
## AWS X-Ray SUPPORT
[AWS X-Ray](https://aws.amazon.com/xray/) is a service that collects data about requests that your application serves.
You can trace AWS Lambda requests and sends segment data
with
pre-install module [AWS::XRay](https://metacpan.org/pod/AWS%3A%3AXRay).
sub
handle {
my
(
$payload
,
$context
) =
@_
;
capture
"myApp"
=>
sub
{
capture
"nested"
=>
sub
{
# do something ...
};
author/perl-stripper/perl-stripper/handler.pl view on Meta::CPAN
123456789101112use
v5.36;
use
utf8;
use
Perl::Strip;
use
Plack::Request;
use
AWS::Lambda::PSGI;
mkdir
'/tmp/.perl-strip'
;
my
$stripper
= Perl::Strip->new(
cache
=>
'/tmp/.perl-strip'
,
examples/cgi/WwwCounter/app.psgi view on Meta::CPAN
1234567891011use
utf8;
use
strict;
use
warnings;
use
Plack::Builder;
use
Plack::App::File;
use
Plack::App::WrapCGI;
my
$count_dir
=
$ENV
{WWWCOUNT_DIR} //
"."
;
for
my
$ext
(
"cnt"
,
"acc"
,
"dat"
) {
open
my
$fh
,
">>"
,
"$count_dir/wwwcount.$ext"
or
die
"cannot touch wwwcount.$ext"
;
close
$fh
;
examples/cgi/WwwCounter/handler.pl view on Meta::CPAN
12345678910use
utf8;
use
warnings;
use
strict;
use
AWS::Lambda::PSGI;
$ENV
{WWWCOUNT_DIR} ||=
"/tmp"
;
chdir
(
$ENV
{
'LAMBDA_TASK_ROOT'
});
my
$app
=
require
"$ENV{'LAMBDA_TASK_ROOT'}/app.psgi"
;
my
$func
= AWS::Lambda::PSGI->wrap(
$app
);
examples/custom-docker/handler.pl view on Meta::CPAN
examples/docker/handler.pl view on Meta::CPAN
examples/hello/handler.pl view on Meta::CPAN
examples/psgi/app.psgi view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Plack::Request;
use
Plack::Builder;
use
Data::Dumper;
return
builder {
mount
'/foo'
=>
sub
{
my
$env
=
shift
;
my
$req
= Plack::Request->new(
$env
);
my
$meth
=
$req
->method;
examples/psgi/handler.pl view on Meta::CPAN
1234567891011use
utf8;
use
warnings;
use
strict;
use
AWS::Lambda::PSGI;
my
$app
=
require
"$ENV{'LAMBDA_TASK_ROOT'}/app.psgi"
;
my
$func
= AWS::Lambda::PSGI->wrap(
$app
);
sub
handle {
my
$payload
=
shift
;
return
$func
->(
$payload
);
examples/s3-get-object/handler.pl view on Meta::CPAN
lib/AWS/Lambda.pm view on Meta::CPAN
300301302303304305306307308309310311312313314315316317318319320=back
L<Paws> is optional. See the "Paws SUPPORT" section.
=head2 AWS X-Ray SUPPORT
L<AWS X-Ray|https://aws.amazon.com/xray/> is a service that collects data about requests that your application serves.
You can trace AWS Lambda requests and sends segment data with pre-install module L<AWS::XRay>.
use utf8;
use warnings;
use strict;
use AWS::XRay qw/ capture /;
sub handle {
my ($payload, $context) = @_;
capture "myApp" => sub {
capture "nested" => sub {
# do something ...
};
lib/AWS/Lambda/Bootstrap.pm view on Meta::CPAN
12345678910111213package
AWS::Lambda::Bootstrap;
use
5.026000;
use
utf8;
use
strict;
use
warnings;
use
HTTP::Tiny;
use
Try::Tiny;
use
AWS::Lambda;
use
AWS::Lambda::Context;
lib/AWS/Lambda/Bootstrap.pm view on Meta::CPAN
221222223224225226227228229230231232233234235236237238239240AWS::Lambda::Bootstrap - the bootrap script
for
AWS Lambda Custom Runtime.
=head1 SYNOPSIS
Save the following script as C<bootstrap>, and then zip it with your perl script.
Now, you can start using Perl in AWS Lambda!
#!perl
use strict;
use warnings;
use utf8;
use AWS::Lambda::Bootstrap;
bootstrap(@ARGV);
Prebuild Perl Runtime Layer includes the C<bootstrap> script.
So, if you use the Layer, no need to include the C<bootstrap> script into your zip.
See L<AWS::Lambda> for more details.
=head1 DESCRIPTION
lib/AWS/Lambda/PSGI.pm view on Meta::CPAN
12345678910111213package
AWS::Lambda::PSGI;
use
5.026000;
use
utf8;
use
strict;
use
warnings;
use
URI::Escape;
use
Plack::Util;
use
bytes ();
use
MIME::Base64;
use
JSON::Types;
use
Encode;
use
Try::Tiny;
lib/AWS/Lambda/PSGI.pm view on Meta::CPAN
150151152153154155156157158159160161162163164165166167168169170$env
->{
'psgi.nonblocking'
} = Plack::Util::FALSE;
$env
->{
'psgix.harakiri'
} = Plack::Util::TRUE;
$env
->{
'psgix.input.buffered'
} = Plack::Util::TRUE;
# inject the request id that compatible with Plack::Middleware::RequestId
if
(
$ctx
) {
$env
->{
'psgix.request_id'
} =
$ctx
->aws_request_id;
$env
->{
'HTTP_X_REQUEST_ID'
} =
$ctx
->aws_request_id;
}
my
$body
= encode_utf8(
$payload
->{body} //
''
);
if
(
$payload
->{isBase64Encoded}) {
$body
= decode_base64
$body
;
}
open
my
$input
,
"<"
, \
$body
;
$env
->{REQUEST_METHOD} =
$payload
->{httpMethod};
$env
->{
'psgi.input'
} =
$input
;
$env
->{CONTENT_LENGTH} //= bytes::
length
(
$body
);
$env
->{REQUEST_URI} =
$payload
->{path};
if
(
$env
->{QUERY_STRING}) {
$env
->{REQUEST_URI} .=
'?'
.
$env
->{QUERY_STRING};
lib/AWS/Lambda/PSGI.pm view on Meta::CPAN
209210211212213214215216217218219220221222223224225226227228229$env
->{
'psgi.nonblocking'
} = Plack::Util::FALSE;
$env
->{
'psgix.harakiri'
} = Plack::Util::TRUE;
$env
->{
'psgix.input.buffered'
} = Plack::Util::TRUE;
# inject the request id that compatible with Plack::Middleware::RequestId
if
(
$ctx
) {
$env
->{
'psgix.request_id'
} =
$ctx
->aws_request_id;
$env
->{
'HTTP_X_REQUEST_ID'
} =
$ctx
->aws_request_id;
}
my
$body
= encode_utf8(
$payload
->{body} //
''
);
if
(
$payload
->{isBase64Encoded}) {
$body
= decode_base64
$body
;
}
open
my
$input
,
"<"
, \
$body
;
$env
->{
'psgi.input'
} =
$input
;
$env
->{CONTENT_LENGTH} //= bytes::
length
(
$body
);
my
$requestContext
=
$payload
->{requestContext};
$env
->{REQUEST_METHOD} =
$requestContext
->{http}{method};
$env
->{REQUEST_URI} =
$payload
->{rawPath};
if
(
$env
->{QUERY_STRING}) {
lib/AWS/Lambda/PSGI.pm view on Meta::CPAN
257258259260261262263264265266267268269270271272273274275276277
$body
->
close
;
}
my
$type
=
$singleValueHeaders
->{
'content-type'
} //
'application/octet-stream'
;
my
$isBase64Encoded
=
$type
!~ m(^text/.*|application/(:?json|javascript|xml))i;
if
(
$isBase64Encoded
) {
$content
= encode_base64
$content
,
''
;
}
else
{
$content
=
try
{
# is valid utf-8 string? try to decode as utf-8.
decode_utf8(
$content
, Encode::FB_CROAK | Encode::LEAVE_SRC);
}
catch
{
# it looks not utf-8 encoding. fallback to base64 encoding.
$isBase64Encoded
= 1;
encode_base64
$content
,
''
;
};
}
return
+{
isBase64Encoded
=> bool
$isBase64Encoded
,
headers
=>
$singleValueHeaders
,
lib/AWS/Lambda/PSGI.pm view on Meta::CPAN
358359360361362363364365366367368369370371372373374375376377378=head1 NAME
AWS::Lambda::PSGI - It translates enevt of Lambda Proxy Integrations in API Gateway and
Application Load Balancer into L<PSGI>.
=head1 SYNOPSIS
Add the following script into your Lambda code archive.
use utf8;
use warnings;
use strict;
use AWS::Lambda::PSGI;
my $app = require "$ENV{'LAMBDA_TASK_ROOT'}/app.psgi";
my $func = AWS::Lambda::PSGI->wrap($app);
sub handle {
return $func->(@_);
}
lib/AWS/Lambda/ResponseWriter.pm view on Meta::CPAN
12345678910111213package
AWS::Lambda::ResponseWriter;
use
5.026000;
use
utf8;
use
strict;
use
warnings;
use
HTTP::Tiny;
my
%DefaultPort
= (
http
=> 80,
https
=> 443,
script/bootstrap view on Meta::CPAN
12345678
t/01_echo.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
Test::Deep;
use
FindBin;
use
BootstrapMock;
use
AWS::Lambda::Context;
my
$payload
= +{
t/02_error.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
FindBin;
use
BootstrapMock;
my
$error
;
my
$bootstrap
= BootstrapMock->new(
handler
=>
"error.handle"
,
runtime_api
=>
"example.com"
,
t/03_init_error.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
FindBin;
use
BootstrapMock;
use
AWS::Lambda::Context;
use
Try::Tiny;
my
$error
;
my
$bootstrap
= BootstrapMock->new(
t/04_handler_not_found.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
FindBin;
use
BootstrapMock;
use
AWS::Lambda::Context;
use
Try::Tiny;
my
$error
;
my
$bootstrap
= BootstrapMock->new(
t/10_lambda_next.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
Test::TCP;
use
HTTP::Server::PSGI;
use
FindBin;
use
Test::Deep;
my
$app_server
= Test::TCP->new(
listen
=> 1,
t/11_lambda_response.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
Test::TCP;
use
HTTP::Server::PSGI;
use
FindBin;
use
AWS::Lambda::Context;
use
Test::Deep;
use
Test::SharedFork;
use
Plack::Request;
t/12_lambda_error.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
Test::TCP;
use
HTTP::Server::PSGI;
use
FindBin;
use
AWS::Lambda::Context;
use
Test::Deep;
use
Test::SharedFork;
use
Plack::Request;
t/13_lambda_init_error.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
Test::TCP;
use
HTTP::Server::PSGI;
use
FindBin;
use
AWS::Lambda::Context;
use
Test::Deep;
use
Test::SharedFork;
use
Plack::Request;
t/14_streaming.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
Test::Deep;
use
FindBin;
use
BootstrapMock;
use
AWS::Lambda::Context;
my
$payload
= +{
t/15_lambda_response_streaming.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
Test::TCP;
use
Starman::Server;
use
FindBin;
use
AWS::Lambda::Context;
use
Test::Deep;
use
Test::SharedFork;
use
Plack::Request;
t/20_psgi.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
FindBin;
use
Plack::Request;
use
Test::Warn;
use
JSON::Types;
use
Encode;
t/20_psgi.t view on Meta::CPAN
192021222324252627282930313233343536373839
my
$name
=
$_
[0];
return
decode_json(slurp(
"$FindBin::Bin/$name"
));
}
sub
slurp_fh {
my
$fh
=
shift
;
my
$data
=
""
;
while
(
$fh
->
read
(
my
$buf
, 4096)) {
$data
.=
$buf
;
}
return
decode_utf8(
$data
);
}
my
$app
= AWS::Lambda::PSGI->new;
subtest
"API Gateway GET Request"
=>
sub
{
my
$input
= slurp_json(
"testdata/apigateway-get-request.json"
);
my
$output
=
$app
->format_input(
$input
);
my
$req
= Plack::Request->new(
$output
);
is
$req
->method,
'GET'
,
'method'
;
my
$content
;
t/20_psgi.t view on Meta::CPAN
204205206207208209210211212213214215216217218219220221222223224my
$response
= [
200,
[
'Content-Type'
=>
'text/plain'
,
'Header-Name'
=>
'value1'
,
'header-name'
=>
'value2'
,
],
[
"Hello"
,
"World"
,
encode_utf8(
"ã“ã‚“ã«ã¡ã¯ä¸–界"
),
]
];
my
$res
=
$app
->format_output(
$response
);
cmp_deeply
$res
, {
isBase64Encoded
=> bool 0,
headers
=> {
'content-type'
=>
'text/plain'
,
'header-name'
=>
'value2'
,
},
multiValueHeaders
=> {
t/21_psgi_response_streaming.t view on Meta::CPAN
12345678910111213use
strict;
use
warnings;
use
utf8;
use
Test::More;
use
FindBin;
use
Plack::Request;
use
Test::Warn;
use
JSON::Types;
use
Encode;
t/21_psgi_response_streaming.t view on Meta::CPAN
171819202122232425262728293031323334353637sub
slurp_json {
my
$name
=
$_
[0];
return
decode_json(slurp(
"$FindBin::Bin/$name"
));
}
sub
slurp_fh {
my
$fh
=
$_
[0];
local
$/;
my
$v
= <
$fh
>;
defined
$v
? decode_utf8(
$v
) :
''
;
}
my
$app
= AWS::Lambda::PSGI->new;
subtest
"array reference"
=>
sub
{
my
$content_type
=
undef
;
my
$buf
=
""
;
my
$res
=
$app
->_handle_response_stream([200, [
"Content-Type"
=>
"text/plain"
], [
"hello"
]]);
my
$responder
=
sub
{
$content_type
=
shift
;
t/test_handlers/echo.pl view on Meta::CPAN
1234567891011use
utf8;
use
strict;
use
warnings;
use
AWS::Lambda;
# an example of echo
# it is called from 01_echo.t
sub
handle {
my
(
$payload
,
$context
) =
@_
;
die
"payload is empty"
unless
$payload
;
die
"context is empty"
unless
$context
;
t/test_handlers/error.pl view on Meta::CPAN