AWS-Lambda
view release on metacpan or search on metacpan
## Use Pre-built Public Lambda Layers
1. Login to your AWS Account and go to the Lambda Console.
2. Create a new function and give it a name and an IAM Role.
3. For the "Runtime" selection, select **Provide your own bootstrap on Amazon Linux 2**.
4. In the "Designer" section of your function dashboard, select the **Layers** box.
5. Scroll down to the "Layers" section and click **Add a layer**.
6. Select the **Provide a layer version ARN** option, then copy/paste the Layer ARN for your region.
7. Click the **Add** button.
8. Click **Save** in the upper right.
9. Upload your code and start using Perl in AWS Lambda!
You can get the layer ARN in your script by using `get_layer_info`.
use AWS::Lambda;
my $info = AWS::Lambda::get_layer_info_al2023(
"5.38", # Perl Version
"us-east-1", # Region
"x86_64", # Architecture ("x86_64" or "arm64", optional, the default is "x86_64")
);
say $info->{runtime_arn}; # arn:aws:lambda:us-east-1:445285296882:layer:perl-5-38-runtime-al2023-x86_64:1
FROM shogo82148/p5-aws-lambda:base-5.38.al2023
# or if you want to use ECR Public.
# FROM public.ecr.aws/shogo82148/p5-aws-lambda:base-5.38.al2023
COPY handler.pl /var/task/
CMD [ "handler.handle" ]
Build the hello-perl container image locally:
$ docker build -t hello-perl .
To check if this is working, start the container image locally using the Lambda Runtime Interface Emulator:
$ docker run -p 9000:8080 hello-perl:latest
Now, you can test a function invocation with cURL.
$ curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
To upload the container image, you need to create a new ECR repository in your account and tag the local image to push it to ECR.
$ aws ecr create-repository --repository-name hello-perl --image-scanning-configuration scanOnPush=true
author/publish-perl-runtimes.pl view on Meta::CPAN
\@regions;
};
for my $zip(glob "$FindBin::Bin/../.perl-layer/dist/perl-*-$suffix-$arch.zip") {
chomp(my $md5 = `openssl dgst -md5 -binary "$zip" | openssl enc -base64`);
my $name = basename($zip, '.zip');
next unless $name =~ /^perl-([0-9]+)-([0-9]+)-/;
my $perl_version = "$1.$2";
my $stack = $perl_version =~ s/[.]/-/r;
for my $region(@$regions) {
$pm->start("$region/$perl_version") and next;
say STDERR "$region/$perl_version: START";
my $object = head_or_put($region, "perl-$stack-$suffix$arch_suffix.zip", $zip, $md5);
my $version = $object->{VersionId} // 'UNKNOWN';
my $stack_name = "lambda-$stack-$suffix$arch_suffix" =~ s/_/-/r;
say STDERR "deploying stack $stack_name in $region...";
run_command('aws', '--region', $region, 'cloudformation', 'deploy',
'--stack-name', $stack_name,
'--template-file', "$FindBin::Bin/cfn-layer-$suffix-$arch.yml",
'--parameter-overrides', "PerlVersion=$perl_version", "Name=perl-$stack-$suffix$arch_suffix", "ObjectVersion=$version");
author/update-aws-lambda-al.pl view on Meta::CPAN
return unless $data;
my ($version, $region, $arn) = @$data;
return unless $version && $region && $arn;
$layers->{$version} //= {};
$layers->{$version}{$region} = $arn;
});
for my $version (@$versions) {
for my $region (@{$regions->{x86_64}}) {
say STDERR "loading $version in $region...";
$pm->start("$version/$region") and next;
my $runtime_stack = "lambda-@{[ $version =~ s/[.]/-/r ]}-runtime";
my $paws_stack = "lambda-@{[ $version =~ s/[.]/-/r ]}-paws";
my ($stdout, $stderr, $exit);
($stdout, $stderr, $exit) = capture {
system("aws --region $region cloudformation describe-stacks --output json --stack-name $runtime_stack | jq -r .Stacks[0].Outputs[0].OutputValue");
};
if ($exit != 0) {
if ($stderr =~ /ValidationError/) {
author/update-aws-lambda-al2.pl view on Meta::CPAN
my ($version, $region, $arn) = @$data;
return unless $version && $region && $arn;
$layers_al2_x86_64->{$version} //= {};
$layers_al2_x86_64->{$version}{$region} = $arn;
});
for my $version (@$versions_al2) {
for my $region (@{$regions->{x86_64}}) {
say STDERR "loading $version in $region...";
$pm_al2_x86_64->start("$version/$region") and next;
my $runtime_stack = "lambda-$version-runtime-al2" =~ s/[._]/-/gr;
my $paws_stack = "lambda-$version-paws-al2" =~ s/[._]/-/gr;
my ($stdout, $stderr, $exit);
($stdout, $stderr, $exit) = capture {
system("aws --region $region cloudformation describe-stacks --output json --stack-name $runtime_stack | jq -r .Stacks[0].Outputs[0].OutputValue");
};
if ($exit != 0) {
if ($stderr =~ /ValidationError/) {
author/update-aws-lambda-al2.pl view on Meta::CPAN
return unless $version && $region && $arch && $arn;
$layers_al2->{$version} //= {};
$layers_al2->{$version}{$region} //= {};
$layers_al2->{$version}{$region}{$arch} = $arn;
});
for my $version (@$versions_al2) {
for my $arch (@$archs) {
for my $region (@{$regions->{$arch}}) {
say STDERR "loading $version in $region...";
$pm_al2->start("$version/$region/$arch") and next;
my $runtime_stack = "lambda-$version-runtime-al2-$arch" =~ s/[._]/-/gr;
my $paws_stack = "lambda-$version-paws-al2-$arch" =~ s/[._]/-/gr;
my ($stdout, $stderr, $exit);
($stdout, $stderr, $exit) = capture {
system("aws --region $region cloudformation describe-stacks --output json --stack-name $runtime_stack | jq -r .Stacks[0].Outputs[0].OutputValue");
};
if ($exit != 0) {
if ($stderr =~ /ValidationError/) {
author/update-aws-lambda-al2023.pl view on Meta::CPAN
return unless $version && $region && $arch && $arn;
$layers_al2023->{$version} //= {};
$layers_al2023->{$version}{$region} //= {};
$layers_al2023->{$version}{$region}{$arch} = $arn;
});
for my $version (@$versions_al2023) {
for my $arch (@$archs) {
for my $region (@{$regions->{$arch}}) {
say STDERR "loading $version in $region...";
$pm_al2023->start("$version/$region/$arch") and next;
my $runtime_stack = "lambda-$version-runtime-al2023-$arch" =~ s/[._]/-/gr;
my $paws_stack = "lambda-$version-paws-al2023-$arch" =~ s/[._]/-/gr;
my ($stdout, $stderr, $exit);
($stdout, $stderr, $exit) = capture {
system("aws --region $region cloudformation describe-stacks --output json --stack-name $runtime_stack | jq -r .Stacks[0].Outputs[0].OutputValue");
};
if ($exit != 0) {
if ($stderr =~ /ValidationError/) {
examples/docker/README.md view on Meta::CPAN
# An Example of Using Prebuilt Docker Images
Build the hello-perl container image locally:
$ docker build -t hello-perl .
To check if this is working, start the container image locally using the Lambda Runtime Interface Emulator:
$ docker run -p 9000:8080 hello-perl:latest
Now, you can test a function invocation with cURL.
$ curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
To upload the container image, you need to create a new ECR repository in your account and tag the local image to push it to ECR.
$ aws ecr create-repository --repository-name hello-perl --image-scanning-configuration scanOnPush=true
lib/AWS/Lambda.pm view on Meta::CPAN
=item 7
Click the B<Add> button.
=item 8
Click B<Save> in the upper right.
=item 9
Upload your code and start using Perl in AWS Lambda!
=back
You can get the layer ARN in your script by using C<get_layer_info>.
use AWS::Lambda;
my $info = AWS::Lambda::get_layer_info_al2023(
"5.38", # Perl Version
"us-east-1", # Region
"x86_64", # Architecture ("x86_64" or "arm64", optional, the default is "x86_64")
lib/AWS/Lambda.pm view on Meta::CPAN
FROM shogo82148/p5-aws-lambda:base-5.38.al2023
# or if you want to use ECR Public.
# FROM public.ecr.aws/shogo82148/p5-aws-lambda:base-5.38.al2023
COPY handler.pl /var/task/
CMD [ "handler.handle" ]
Build the hello-perl container image locally:
$ docker build -t hello-perl .
To check if this is working, start the container image locally using the Lambda Runtime Interface Emulator:
$ docker run -p 9000:8080 hello-perl:latest
Now, you can test a function invocation with cURL.
$ curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
To upload the container image, you need to create a new ECR repository in your account and tag the local image to push it to ECR.
$ aws ecr create-repository --repository-name hello-perl --image-scanning-configuration scanOnPush=true
lib/AWS/Lambda/Bootstrap.pm view on Meta::CPAN
=encoding utf-8
=head1 NAME
AWS::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.
xt/21_mojoapp.pl view on Meta::CPAN
use Mojolicious::Lite -signatures;
get '/get-link' => sub ($c) {
$c->render(text => $c->url_for('controller1'));
};
get '/controller1' => sub ($c) {
}, 'controller1';
app->start;
( run in 0.429 second using v1.01-cache-2.11-cpan-0d8aa00de5b )