The basics of using Serverless Framework for AWS Lambda PHP applications.
- Install Serverless Framework by following the Quick Start
- Set up your AWS credentials
- Create php binary layer and upload to AWS by following steps in
php-runtime/README.md
- Write your serverless application (!) - the default is in
hello-world/handler.php
- Run
sls deploy
to deploy to Lambda - Run
sls invoke -f hello -l
to invoke your function
As we've used Docker to create the runtime, you can test locally using the Dockerfile
in hello-world
:
$ cd hello-world
$ docker build -t lambda-php-test . && docker run lambda-php-test handler.hello '{"name": "world"}'
The signature for the PHP function is:
function main($eventData) : array
Hello world looks like:
<?php
function hello($eventData) : array
{
return ["msg" => "Hello from PHP " . PHP_VERSION];
}