Notes on software development

Using AWS Lambda Layers for PHP

Until recently AWS Lambda did not support PHP, but with the advent of the runtime API and layers, now we able to implement an AWS Lambda runtime in any programming language including PHP. Each layer can contain libraries, a custom runtime, or other dependencies. You can create layers, or use layers published by AWS and other AWS customers.

There is a great practical example of creating a Custom Runtime for PHP if you want to build a PHP runtime layer by yourself. In this article, we'll use partner supported PHP layer for Lambda from stackery for a quick understanding of its use.

1. Create a Lambda function from scratch.


2. Click "Layers" and then "Add a layer"


3. Choose "Provide a layer version ARN". Here we need to specify an ARN.

You can choose the desired version here. Currently, the latest available Lambda Layer Version ARNs for PHP 7.3 and 7.1 are:




4. Create index.php file and change handler to index.php.

The content of our function is:

echo "Hello from the AWS Lambda!";


5. Add API Gateway trigger with the HTTP API template.


6. Now we have the API endpoint which will trigger our function.


7. Click on the API endpoint link and you'll see the result of our function


What's next?

I recommend reading the article "AWS Lambda Custom Runtime for PHP: A Practical Example" to deep dive in creating custom runtime for PHP and also watching video from re:Invent 2018 "AWS Lambda Layers, the Runtime API, and Nested Applications"