AWS-Lambda
view release on metacpan or search on metacpan
lib/AWS/Lambda.pm view on Meta::CPAN
=item 1
Login to your AWS Account and go to the Lambda Console.
=item 2
Create a new layer and give it a name.
=item 3
For the "Code entry type" selection, select B<Upload a file from Amazon S3>.
=item 4
In the "License" section, input L<https://github.com/shogo82148/p5-aws-lambda/blob/main/LICENSE>.
=item 5
Click B<Create> button.
=item 6
Use the layer created. For detail, see Use Prebuilt Public Lambda Layer section.
=back
URLs for Zip archives are here.
C<https://shogo82148-lambda-perl-runtime-$REGION.s3.amazonaws.com/perl-$VERSION-runtime-al2023-$ARCHITECTURE.zip>
=head2 Use Pre-built Docker Images
Prebuilt Docker Images based on L<https://gallery.ecr.aws/lambda/provided> are available.
You can pull from L<https://gallery.ecr.aws/shogo82148/p5-aws-lambda> or L<https://hub.docker.com/r/shogo82148/p5-aws-lambda>,
build your custom images and deploy them to AWS Lambda.
Here is an example of Dockerfile.
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
$ docker tag hello-perl:latest 123412341234.dkr.ecr.sa-east-1.amazonaws.com/hello-perl:latest
$ aws ecr get-login-password | docker login --username AWS --password-stdin 123412341234.dkr.ecr.sa-east-1.amazonaws.com
$ docker push 123412341234.dkr.ecr.sa-east-1.amazonaws.com/hello-perl:latest
Finally, create new function using awscli.
$ aws --region "$REGION" --profile "$PROFILE" lambda create-function \
--function-name "hello-perl" \
--code ImageUri=123412341234.dkr.ecr.sa-east-1.amazonaws.com/hello-perl:latest \
--handler "handler.handle" \
--runtime provided.al2023 \
--role arn:aws:iam::xxxxxxxxxxxx:role/service-role/lambda-custom-runtime-perl-role
=head2 Run in Local using Docker
Prebuilt Docker Images based on L<https://hub.docker.com/r/lambci/lambda/> are available.
You can pull from L<https://gallery.ecr.aws/shogo82148/p5-aws-lambda> or L<https://hub.docker.com/r/shogo82148/p5-aws-lambda>,
and build zip archives to deploy.
# Install the dependency.
docker run --rm -v $(PWD):/var/task shogo82148/p5-aws-lambda:build-5.38.al2023 \
cpanm --notest --local-lib extlocal --no-man-pages --installdeps .
# run an event.
docker run --rm -v $(PWD):/var/task shogo82148/p5-aws-lambda:5.38.al2023 \
handler.handle '{"some":"event"}'
=head2 Pre-installed modules
The following modules are pre-installed for convenience.
=over
=item L<AWS::Lambda>
=item L<AWS::XRay>
=item L<JSON>
=item L<Cpanel::JSON::XS>
=item L<JSON::MaybeXS>
=item L<YAML>
=item L<YAML::Tiny>
=item L<YAML::XS>
=item L<Net::SSLeay>
=item L<IO::Socket::SSL>
=item L<Mozilla::CA>
=item L<local::lib>
=back
L<Paws> is optional. See the "Paws SUPPORT" section.
=head2 AWS X-Ray SUPPORT
( run in 1.016 second using v1.01-cache-2.11-cpan-98e64b0badf )