A Symfony Runtime implementation for AWS Lambda. Run a standard Symfony application on Lambda with no code changes to your controllers, services, or templates.
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.
composer require likeuntomurphy/serverless-runtimeCreate 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.
- 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
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.jsonThe response contains the exit code and output:
{"exitCode": 0, "output": "..."}| 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) |
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.
- PHP >= 8.5
symfony/runtime^8.0symfony/http-kernel^8.0symfony/http-client^8.0
MIT