PHP for AWS Lambda via Serverless Framework using Symfony components for dependency injection.
Latest version is on master.
AWS Lambda lets you run code without thinking about servers. Right now you can author your AWS Lambda functions in several langauges natively, but not PHP. This project aims to provide a fully featured shim for authoring your AWS Lambda functions in PHP.
More information about how this works and its performance characteristics can be found on my blog post.
<?php
use Raines\Serverless\Context;
use Raines\Serverless\Handler;
class HelloHandler implements Handler
{
public function handle(array $event, Context $context)
{
return [
'statusCode' => 200,
'body' => 'Hello World!',
];
}
}
Event Data | Context | Logging | Exceptions | Environment | API Gateway |
---|---|---|---|---|---|
Install this project:
serverless install --url https://github.com/araines/serverless-php
Currently serverless install
does not work with Git LFS.
Hopefully this will be supported in the future,
but for the moment here are your options:
- Rebuild the PHP binary (described later in this document)
- Download the PHP binary directly from GitHub
- Instead of using
serverless install
, ensure you have Git LFS installed on your system and clone the repository.
composer install -o --no-dev
serverless deploy
serverless invoke local -f hello
serverless invoke -f hello
The PHP binary can be built with any flags you require and at any version.
sh buildphp.sh
Edit buildphp.sh
and dockerfile.buildphp
to alter it.
- Robert Anderson for the inspiration and base for this project