Skip to content

Commit decbc81

Browse files
authored
Merge pull request #15 from xp-forge/feature/al2
Upgrade to Amazon Linux 2
2 parents b1066b5 + cb14b5b commit decbc81

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ $ xp lambda test Greet '{"name":"Timm"}'
4545
START RequestId: 9ff45cda-df9b-1b8c-c21b-5fe27c8f2d24 Version: $LATEST
4646
END RequestId: 9ff45cda-df9b-1b8c-c21b-5fe27c8f2d24
4747
REPORT RequestId: 9ff45cda-df9b-1b8c-c21b-5fe27c8f2d24 Init Duration: 922.19 ms...
48-
4948
"Hello Timm from PHP 8.0.10 via test @ us-east-1"
5049
```
5150

52-
*This functionality is provided by the great [LambCI Docker image](https://github.com/lambci/docker-lambda)!*
51+
*This functionality is provided by the [AWS Lambda base images for custom runtimes](https://gallery.ecr.aws/lambda/provided)*
5352

5453
Setup
5554
-----
@@ -89,7 +88,7 @@ $ aws lambda create-function \
8988
--function-name greet \
9089
--handler Greet \
9190
--zip-file fileb://./function.zip \
92-
--runtime provided \
91+
--runtime provided.al2 \
9392
--role "arn:aws:iam::XXXXXXXXXXXX:role/service-role/InvokeLambda" \
9493
--region us-east-1 \
9594
--layers "arn:aws:lambda:us-east-1:XXXXXXXXXXXX:layer:lambda-xp-runtime:1"

src/main/php/xp/lambda/CreateRuntime.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function run(): int {
2828
$code= "echo ' => PHP ', PHP_VERSION, ' & Zend ', zend_version(), ' @ ', php_uname(), PHP_EOL, ' => ', implode(' ', get_loaded_extensions()), PHP_EOL;";
2929
Console::writeLine();
3030
Console::writeLine("[+] Running {$runtime}\e[34m");
31-
$this->passthru(['run', '--rm', $runtime, '/opt/php/bin/php', '-r', $code]);
31+
$this->passthru(['run', '--rm', '--entrypoint=/opt/php/bin/php', $runtime, '-r', $code]);
3232
Console::writeLine("\e[0m");
3333

3434
// Extract runtime

src/main/php/xp/lambda/Dockerfile.runtime

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
FROM amazonlinux:2018.03.0.20210721.0 as builder
1+
FROM public.ecr.aws/lambda/provided:al2 as builder
22

33
ARG php_version="?.?.?"
44
ARG xp_version="?.?.?"
55

6-
# Install PHP build dependencies
7-
RUN curl -O http://mirror.centos.org/centos/7/os/x86_64/Packages/bison-3.0.4-2.el7.x86_64.rpm
8-
96
RUN yum clean all && yum install -y \
107
autoconf \
118
gcc \
@@ -15,8 +12,9 @@ RUN yum clean all && yum install -y \
1512
openssl-devel \
1613
libxml2-devel \
1714
tar \
15+
gzip \
1816
zip \
19-
bison-3.0.4-2.el7.x86_64.rpm
17+
bison
2018

2119
# Build PHP
2220
RUN curl -L https://github.com/php/php-src/archive/php-${php_version}.tar.gz | tar -xvz
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
ARG php_version="?.?.?"
22
ARG xp_version="?.?.?"
33

4-
FROM lambda-xp-runtime:${php_version} as runtime
4+
FROM lambda-xp-runtime:${php_version} as build
55

6-
FROM lambci/lambda:provided
6+
FROM public.ecr.aws/lambda/provided:al2
77

8-
COPY --from=runtime /opt/php/bin/ /opt/bin/
8+
COPY --from=build /opt/php/bin/ /opt/bin/
99

10-
COPY --from=runtime /opt/php/bootstrap /opt/bootstrap
10+
COPY --from=build /opt/php/bootstrap /var/runtime/bootstrap
11+
12+
# Overwrite AWS lambda entrypoint
13+
RUN echo $'#!/bin/sh\n\n\
14+
export _HANDLER="$1"\n\
15+
/usr/local/bin/aws-lambda-rie /var/runtime/bootstrap --log-level error &\n\
16+
pid=$!\n\
17+
curl -s "http://localhost:8080/2015-03-31/functions/function/invocations" -d "$2"\n\
18+
kill -2 $pid\n\
19+
echo' > /lambda-entrypoint.sh
1120

1221
ENV TZ UTC

0 commit comments

Comments
 (0)