First: run the docker image of the Lambda runtime (https://docs.aws.amazon.com/es_es/lambda/latest/dg/current-supported-versions.html):
docker run -it --name php-lambda-layer --rm amazonlinux:2017.03.1.20170812 bash
Inside docker, run the following commands:
cd
yum update -y
yum install autoconf bison gcc gcc-c++ libcurl-devel libxml2-devel openssl-devel git tree zip vim python36 python36-pip libicu-devel unzip diff libpng-devel -y
# Compile a moder version of openssl than included in the docker image
curl -sL http://www.openssl.org/source/openssl-1.0.1k.tar.gz | tar -xvz
cd openssl-1.0.1k
./config
make
make install
# PHP requires libzip >= 0.11, but the docker image has 0.10
# The latest source versions ob libzip require a cmake version that
# is not included in the docker image, so we use a intermediate
# version of libzip.
# Compile libzip
cd
curl -LO https://nih.at/libzip/libzip-1.2.0.tar.gz
tar zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make
make install
# Compile php
cd
mkdir ~/php-7-bin
curl -sL https://github.com/php/php-src/archive/php-7.2.16.tar.gz | tar -xvz
cd ~/php-src-php-7.2.16
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
./buildconf --force
./configure --prefix=/root/php-7-bin/ --with-openssl=/usr/local/ssl --with-curl --with-zlib --enable-intl --enable-mbstring --with-pdo-mysql --with-curl --with-zlib --with-gd --enable-bcmath --enable-zip --with-libzip=/usr/local/lib --without-pear --enable-shared=no --enable-static=yes
make
make install
~/php-7-bin/bin/php -v
~/php-7-bin/bin/php -m
# Install composer
cd
curl -sS https://getcomposer.org/installer | ~/php-7-bin/bin/php
# Create runtime
mkdir ~/php-runtime
cd ~/php-runtime
curl -qL https://gist.github.com/okelet/afe16efea9b89ce90e4690dd752cb4ae/raw > bootstrap
chmod 755 bootstrap
~/php-7-bin/bin/php ~/composer.phar require guzzlehttp/guzzle
rm -f ~/runtime.zip
cd ~/php-7-bin
zip -r ~/runtime.zip bin/php
cd ~/php-runtime
zip -r ~/runtime.zip .
Then, WITH docker session still alive, copy from the host the generated runtime.zip file:
docker cp php-lambda-layer:/root/runtime.zip .
Then upload the new file as a layer and set the new layer in the Lambda function.