AWS-Lambda

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - perl 5.30.0 is released
    - Support the AWS Asia Pacific (Hong Kong) Region (ap-east-1)

0.0.4 2019-04-20T07:09:46Z
    - perl 5.28.2 is released

0.0.3 2019-04-18T06:17:14Z
    - Added missing prereq URI::Escape as suggested by CPANTS. #13 (thx @manwar)

0.0.2 2019-04-17T07:14:14Z
    - set SCRIPT_NAME environment value (fixes #7)
    - install Plack::Middleware::ReverseProxy

0.0.1 2019-03-10T06:01:37Z
    - original version

author/build-paws-al2.sh  view on Meta::CPAN

#!/usr/bin/env bash
# helper script for build-paws-layer-al2.sh
# you should not run this script directly.

set -uex

TAG=$1

PAWS_VERSION=0.46

# provided.al2 lacks expat.
yum install -y expat expat-devel
cp /usr/lib64/libexpat.so.* /opt-lib/

case $(uname -m) in

author/build-paws-al2023.sh  view on Meta::CPAN

#!/usr/bin/env bash
# helper script for build-paws-layer-al2023.sh
# you should not run this script directly.

set -uex

TAG=$1

PAWS_VERSION=0.46

# install development packages
dnf install -y glibc-langpack-en expat-devel

case $(uname -m) in
  "x86_64")

author/build-paws-layer-al2.sh  view on Meta::CPAN

    $0 5.38.3 5-38 arm64
    exit 0
fi

PERL_VERSION=$1
TAG=$2
PLATFORM=$3

OPT="$ROOT/.perl-layer/$PERL_VERSION-paws.al2"
DIST="$ROOT/.perl-layer/dist"
set -uex

# sanity check of required tools
command -v parallel # GNU parallel

# clean up
rm -rf "$OPT-$PLATFORM"
mkdir -p "$OPT-$PLATFORM/lib/perl5/site_perl"
rm -f "$DIST/perl-$TAG-paws-al2-$PLATFORM.zip"

DOCKER_PLATFORM=linux/unknown

author/build-paws-layer-al2023.sh  view on Meta::CPAN

    $0 5.38.3 5-38 arm64
    exit 0
fi

PERL_VERSION=$1
TAG=$2
PLATFORM=$3

OPT="$ROOT/.perl-layer/$PERL_VERSION-paws.al2023"
DIST="$ROOT/.perl-layer/dist"
set -uex

# sanity check of required tools
command -v parallel # GNU parallel

# clean up
rm -rf "$OPT-$PLATFORM"
mkdir -p "$OPT-$PLATFORM/lib/perl5/site_perl"
rm -f "$DIST/perl-$TAG-paws-al2023-$PLATFORM.zip"

DOCKER_PLATFORM=linux/unknown

author/build-perl-al2.sh  view on Meta::CPAN

#!/usr/bin/env bash
# helper script for build-perl-runtime-al2.sh
# you should not run this script directly.

set -uex

PERL_VERSION=$1

NET_SSLEAY_VERSION=1.94
CARTON_VERSION=v1.0.35
AWS_XRAY_VERSION=0.12
JSON_VERSION=4.10
JSON_XS_VERSION=4.03
CPANEL_JSON_XS_VERSION=4.39
JSON_MAYBEXS_VERSION=1.004008

author/build-perl-al2023.sh  view on Meta::CPAN

#!/usr/bin/env bash
# helper script for build-perl-runtime-al2023.sh
# you should not run this script directly.

set -uex

PERL_VERSION=$1

NET_SSLEAY_VERSION=1.94
CARTON_VERSION=v1.0.35
AWS_XRAY_VERSION=0.12
JSON_VERSION=4.10
JSON_XS_VERSION=4.03
CPANEL_JSON_XS_VERSION=4.39
JSON_MAYBEXS_VERSION=1.004008

author/build-perl-runtime-al2.sh  view on Meta::CPAN

    $0 5.38.3 5-38 arm64
    exit 0
fi

PERL_VERSION=$1
TAG=$2
PLATFORM=$3

OPT="$ROOT/.perl-layer/${PERL_VERSION}.al2"
DIST="$ROOT/.perl-layer/dist"
set -uex

# clean up
rm -rf "$OPT-$PLATFORM"
mkdir -p "$OPT-$PLATFORM"
rm -f "$DIST/perl-$TAG-runtime-al2-$PLATFORM.zip"

DOCKER_PLATFORM=linux/unknown
case $PLATFORM in
    "x86_64") DOCKER_PLATFORM=linux/amd64;;
    "arm64") DOCKER_PLATFORM=linux/arm64;;

author/build-perl-runtime-al2023.sh  view on Meta::CPAN

    $0 5.38.3 5-38 arm64
    exit 0
fi

PERL_VERSION=$1
TAG=$2
PLATFORM=$3

OPT="$ROOT/.perl-layer/${PERL_VERSION}.al2023"
DIST="$ROOT/.perl-layer/dist"
set -uex

# clean up
rm -rf "$OPT-$PLATFORM"
mkdir -p "$OPT-$PLATFORM"
rm -f "$DIST/perl-$TAG-runtime-al2023-$PLATFORM.zip"

DOCKER_PLATFORM=linux/unknown
case $PLATFORM in
    "x86_64") DOCKER_PLATFORM=linux/amd64;;
    "arm64") DOCKER_PLATFORM=linux/arm64;;

author/deploy-s3-stack.sh  view on Meta::CPAN

#!/usr/bin/env bash

ROOT=$(cd "$(dirname "$0")" && pwd)

set -xue

"$ROOT/validate-account.sh" || exit 2

while read -r REGION; do
aws --region "$REGION" cloudformation deploy \
    --stack-name "lambda-perl5-runtime-s3" \
    --template-file "${ROOT}/cfn-s3.yml" || true
done < "$ROOT/regions-x86_64.txt"

author/update-dependencies.sh  view on Meta::CPAN

#!/bin/bash

set -eux

cd "$(dirname "$0")"

function update {
    MODULE=$1
    VERSION_NAME=$2
    FILE_NAME=$3
    VERSION=$(curl -sSL "https://fastapi.metacpan.org/v1/release/$MODULE" | jq -r '.version')

    echo "update $MODULE $VERSION_NAME $FILE_NAME $VERSION"

author/validate-account.sh  view on Meta::CPAN

#!/usr/bin/env bash

set -xue

AWS_ACCOUNT=$(aws sts get-caller-identity | jq -r .Account)

if [[ "$AWS_ACCOUNT" != 445285296882 ]]; then
    echo "Invalid AWS Account: $AWS_ACCOUNT" > /dev/stderr
    exit 2
fi

author/validate-template.sh  view on Meta::CPAN

#!/bin/bash

ROOT=$(cd "$(dirname "$0")" && pwd)
EXITCODE=0

set -xu
for TEMPLATE in "$ROOT"/*.yml; do
    aws cloudformation validate-template --region ap-northeast-1 --template-body "file://${TEMPLATE}" || EXITCODE=1
done

exit "$EXITCODE"

examples/cgi/WwwCounter/readme.html  view on Meta::CPAN

<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">
<title>WwwCounter Ver3.15利用メモ - とほほのWWW入門</title>
<style type="text/css">
<!--
BODY {
    color: #333333;
}
H2 {
    width: 100%;
    font-weight: bold;
    color: #ffffff;

examples/cgi/WwwCounter/sample.html  view on Meta::CPAN

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WwwCounterサンプル - とほほのWWW入門</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<style>
.i { margin-left: 1rem; }
</style>
</head>
<body>
<h2 align="center">WwwCounterサンプル</h2>
<hr>

examples/cgi/WwwCounter/style3.css  view on Meta::CPAN

 *   .index-title: index-title
 * Code
 *   .tab : tab
 *   .c : code box
 *   .c2 : code box with tab
 *   .dos : dos command
 * Table
 *   .tb0 : table
 *   .tb1 : table
 *   .vl : table vertical line (with .tb1)
 * Reset
 *   .reset : reset
 */

/* Font */
body {
  /* font-family: verdana, 'Meiryo UI', 'メイリオ', 'MS Pゴシック', 'ヒラギノ角ゴシック', sans-selif; */
  font-family: 'Meiryo UI', 'メイリオ', 'MS Pゴシック', 'ヒラギノ角ゴシック', sans-selif;
}
pre, code {
  font-family: Consolas, 'Meiryo UI', 'メイリオ', 'MS Pゴシック', 'ヒラギノ角ゴシック', sans-selif;
}

examples/cgi/WwwCounter/style3.css  view on Meta::CPAN

h2 {
  font-size: 16pt;
  padding: 6px;
  margin: 0 0 8px 0;
  border-top: 5px solid #469;
  border-bottom: 5px solid #469;
}
h2::before {
  content: url("image/popase.gif") " ";
}
h2.reset::before {
  content: "";
}
h3 {
  padding: 0 0 0 4px;
  font-size: 16pt;
  border-left: 4px solid #469;
}
h4 {
  margin: 1em 0 1em 0;
  font-size: 13pt;
  padding: 3px 3px 1px 0px;
  border-bottom: 1px solid #ccc;
}
h5 {
  margin: 0;
}
h5 i {
  font-weight: normal;
}
h1.reset, h2.reset,
h3.reset, h4.reset,
h5.reset, h6.reset {
  margin: .5em 0;
  padding: 0;
  border: none;
}
h1.reset {
  font-size: 2em;
}
h2.reset {
  font-size: 1.5em;
}
h3.reset {
  font-size: 1.17em;
}
h4.reset {
  font-size: 1em;
}
p {
  margin: .7em 0 .7em 0;
}
ul {
  margin-left: -1em;
}
em {
  color: #f00;
  font-style: normal;
}
em.reset {
  color: inherit;
  font-style: italic;
}
a:link, a:visited {
  color: #113366;
}
a:hover {
  color: #f00;
}
a.reset:hover {
  color: inherit;
}

/* Multicolmn */
.clearfix:after {
  content: ".";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;

examples/cgi/WwwCounter/style3.css  view on Meta::CPAN

  color: #456;
  font-weight: bold;
}
.tb1 th {
  text-align: left;
}
.tb1.vl th, .tb1.vl td {
  border: 1px solid #999;
}
.tb1.js {
  width: unset;
}

/* HTML Reference */
.htmlelem {
  background-color: #e0eeff;
  padding: 6px 6px 12px 6px;
}
.htmlelem dt {
  margin-top: .6em;
  font-weight: bold;

examples/cgi/WwwCounter/wwwcount.cgi  view on Meta::CPAN


#
# CGIが使用できるかテストを行う。
#
sub test {
	print "Content-type: text/html\n";
	print "\n";
	print "<!doctype html>\n";
	print "<html>\n";
	print "<head>\n";
	print "<meta charset='utf-8'>\n";
    print "<title>Test</title>\n";
    print "</head>\n";
	print "<body>\n";
	print "<p>OK. CGIスクリプトは正常に動いています。</p>\n";
	if ($g_mailto ne "") {
		if (! -f $g_sendmail) {
			print "<p>ERROR: $g_sendmail が存在しません。</p>\n";
		}
	}
	if (!-d $g_lock_dir) {

examples/cgi/samconfig.toml  view on Meta::CPAN

version = 0.1
[author]
[author.deploy]
[author.deploy.parameters]
stack_name = "www-counter"
s3_bucket = "aws-sam-cli-managed-default-samclisourcebucket-10nboesix5it7"
s3_prefix = "www-counter"
region = "ap-northeast-1"
confirm_changeset = true
capabilities = "CAPABILITY_IAM"

examples/s3-get-object/deploy.sh  view on Meta::CPAN

#!/bin/bash

set -eux

ROOT=$(cd "$(dirname "$0")" && pwd)
BUCKET=$1
STACK=$2
PREFIX=$3

aws cloudformation package \
    --template-file "$ROOT/template.yaml" \
    --output-template-file "$ROOT/packaged.yaml" \
    --s3-bucket "$BUCKET"

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

    my $task_root = $args{task_root} // $ENV{'LAMBDA_TASK_ROOT'} // die '$LAMBDA_TASK_ROOT is not found';
    my $self = bless +{
        task_root      => $task_root,
        handler        => $handler,
        function_name  => $function,
        runtime_api    => $runtime_api,
        api_version    => $api_version,
        next_event_url => "http://${runtime_api}/${api_version}/runtime/invocation/next",
        http           => HTTP::Tiny->new(
            # XXX: I want to disable timeout, but it seems HTTP::Tiny does not support it.
            # So, I set a long timeout.
            timeout => 365*24*60*60, # 365 days
        ),
    }, $class;
    return $self;
}

sub handle_events {
    my $self = shift;
    $self->_init or return;
    while(1) {

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

sub format_input {
    my ($self, $payload, $ctx) = @_;
    if (my $context = $payload->{requestContext}) {
        if ($context->{elb}) {
            # Application Load Balancer https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
            return $self->_format_input_v1($payload, $ctx);
        }
    }
    if (my $version = $payload->{version}) {
        if ($version =~ /^1[.]/) {
            # API Gateway for REST https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
            return $self->_format_input_v1($payload, $ctx);
        }
        if ($version =~ /^2[.]/) {
            # API Gateway for HTTP https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
            return $self->_format_input_v2($payload, $ctx);
        }
    }
    return $self->_format_input_v1($payload, $ctx);
}

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

}

sub _format_response_stream {
    my ($self, $status, $headers) = @_;
    my $headers_hash = {};
    my $cookies = [];

    Plack::Util::header_iter($headers, sub {
        my ($k, $v) = @_;
        $k = lc $k;
        if ($k eq 'set-cookie') {
            push @$cookies, string $v;
        } elsif (exists $headers_hash->{$k}) {
            $headers_hash->{$k} = ", $v";
        } else {
            $headers_hash->{$k} = string $v;
        }
    });

    return +{
        statusCode => number $status,

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


    my $app = require "$ENV{'LAMBDA_TASK_ROOT'}/app.psgi";
    my $func = AWS::Lambda::PSGI->wrap($app);

    sub handle {
        return $func->(@_);
    }

    1;

And then, L<Set up Lambda Proxy Integrations in API Gateway|https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html> or
L<Lambda Functions as ALB Targets|https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html>

=head1 DESCRIPTION

=head2 Streaming Response

L<AWS::Lambda::PSGI> supports L<response streaming|https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html>.
The function urls's invoke mode is configured as C<"RESPONSE_STREAM">, and Lambda environment variable "PERL5_LAMBDA_PSGI_INVOKE_MODE" is set to C<"RESPONSE_STREAM">.

    ExampleApi:
        Type: AWS::Serverless::Function
        Properties:
            FunctionUrlConfig:
                AuthType: NONE
                InvokeMode: RESPONSE_STREAM
            Environment:
                Variables:
                PERL5_LAMBDA_PSGI_INVOKE_MODE: RESPONSE_STREAM



( run in 1.398 second using v1.01-cache-2.11-cpan-49f99fa48dc )