likeuntomurphy / serverless-runtime
Symfony Runtime implementation for AWS Lambda
Package info
github.com/likeuntomurphy/serverless-runtime
pkg:composer/likeuntomurphy/serverless-runtime
Requires
- php: >=8.5
- symfony/http-client: ^8.0
- symfony/http-kernel: ^8.0
- symfony/runtime: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.0
- symfony/framework-bundle: ^8.0
This package is auto-updated.
Last update: 2026-04-08 11:57:40 UTC
README
A Symfony Runtime implementation for AWS Lambda. Run a standard Symfony application on Lambda with no code changes to your controllers, services, or templates.
How it works
The Symfony Runtime component decouples your application from how it's executed. This package provides a Runtime that translates API Gateway v2.0 (HTTP API) events into Symfony Request objects and returns the Response as a Lambda-compatible payload. Console commands are supported via a console key in the event payload.
Your application code stays the same whether it runs on a traditional web server or on Lambda.
Installation
composer require likeuntomurphy/serverless-runtime
Usage
Create a bootstrap file in your project root:
#!/opt/php/bin/php <?php use App\Kernel; $_SERVER['APP_RUNTIME'] = Likeuntomurphy\Serverless\Runtime\Runtime::class; require __DIR__.'/vendor/autoload_runtime.php'; return function (array $context) { return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); };
This is identical to a standard Symfony public/index.php — the only difference is the APP_RUNTIME override.
What it handles
- HTTP requests via API Gateway v2.0 (HTTP API) payloads
- Form submissions with
application/x-www-form-urlencodedbody parsing - Cookies from both the
cookiesarray (API Gateway v2.0) and thecookieheader - Base64-encoded bodies are decoded automatically when
isBase64Encodedis true - Multi-value response headers are joined per RFC 9110
- Set-Cookie headers are returned via the API Gateway
cookiesarray - Console commands via a
{"console": "cache:clear"}event payload - Kernel termination is called after each request for cleanup
Console commands
Invoke any Symfony console command from Lambda:
aws lambda invoke --function-name my-app \
--payload '{"console": "cache:clear"}' \
--cli-binary-format raw-in-base64-out \
/tmp/output.json
The response contains the exit code and output:
{"exitCode": 0, "output": "..."}
Environment variables
| Variable | Description |
|---|---|
AWS_LAMBDA_RUNTIME_API |
Set automatically by Lambda |
APP_ENV |
Symfony environment (resolved by SymfonyRuntime) |
APP_DEBUG |
Debug mode (resolved by SymfonyRuntime) |
APP_RUNTIME_MODE |
Set to web=1 for proper error rendering in Lambda's CLI SAPI |
DEFAULT_URI |
Fallback host for request generation (e.g. https://example.com) |
Architecture
Two classes:
RuntimeextendsSymfonyRuntimeand overridesgetRunner()to return aRunnerwhen the application is aKernelInterface.RunnerimplementsRunnerInterfaceand runs the Lambda event loop: poll for events, translate to Symfony requests, return responses.
For non-kernel applications (e.g. a standalone Console\Application), the runtime delegates to the parent SymfonyRuntime.
Requirements
- PHP >= 8.5
symfony/runtime^8.0symfony/http-kernel^8.0symfony/http-client^8.0
License
MIT