AWS Lambda is powered by Docker containers. If you provide a script, Lambda will download the script and execute it within a Docker container. If you provide a zip file, Lambda will download the zip and execute the contents within a Docker contianer.
The docker containers Lambda runs are Amazon Linux. Amazon Lambda does not natively support php, however we can use php if we compile a static single-binary version which can be called by another language that Lambda does support, like NodeJS.
How to compile php 5.6.6 for Lambda
There is an Amazon Linux docker container available. We will download the docker container and use that to compile our php binary.
Amazon Linux contains the latest security fixes for OpenSSL. However, as of January 2018, the Docker Images used in Lambda do not contain the latest OpenSSL packages. This is a problem because while you will be able to compile your php binary for use with Lambda, you will not be able to run it. To make matters worse, Amazon has removed the previous version of the OpenSSL package from their repositories. So we need a version of PHP compiled against the previous OpenSSL release so that it will run inside of the AWS Lambda docker container.
Getting OpenSSL 1.0.1k
The package is not available in the Amazon Linux Mirrors
Ideally you could solve this issue by downgrading the openssl package and using the yum versionlock plugin to keep the package from being upgraded.
Unfortunately the outdated openssl-1.0.1k packages are no longer available in the Amazon Linux mirrors. Amazon’s practice of purging the outdated packages from the mirror is not a bad practice, but it does prevent us from getting the package we need to build against.
Using a CentOS package
Luckily Amazon Linux is based on RHEL, so we can substitute a package from CentOS for a relative amount of compatibility. Amazon does upgrade a LOT of the base system so this little trick doesn’t always work. However, in this instance, we are able to locate the packages on http://rpm.pbone.net/