This repo contains an implementation of PHP runtime layer with AWS Lambda. Everything you need is already included.
Files:
runtime/php
- Statically compiled PHP 7.2.11 on alinux 2017.03runtime/bootstrap
- This is a Bash script. This initizlizes and starts the PHP runtimeruntime/runtime.php
- This contains the interations with AWS runtime API and the main logic to execute the function handlerfunction/Function.php
- Sample lambda function
This runtime expects the function handler in AWS Lambda configuration in the form filename.handler
. This means that if you configure AWS lambda's handler field as filename.handler
the runtime layer will look for a file fielname.php
in your function code and execute the function handler
passing in the event payload as the first argument. Refer to file function/Function.php
in this repositiory for example.
To use this runtime:
- Download or clone this repo ⬇️
- Log in to AWS and go to the Lambda service area
- Click on Layers and "Create Layer"
- Name the layer and upload the zip file created in above step ⬆️
- Take a note of the ARN generated in the layer 📝
- Create a Lambda function from scratch. Select custom runtime 🏇
- Click on Layers in AWS "Lambda Designer" area to reveal layer options click "Add Layer"
- Paste in the ARN from the above step as the source of the layer and save
- Define the handler in lambda function as
function.handler
in the "Function Code" area - Copy code from
function.php
into the lambda funtion created above ✏️
You will see "hello" returned upon testing.
You now are running PHP in lambda. 🎉👍