Download the PHP package dayspring-tech/lambda-bundle without Composer
On this page you can find all versions of the php package dayspring-tech/lambda-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dayspring-tech/lambda-bundle
More information about dayspring-tech/lambda-bundle
Files in dayspring-tech/lambda-bundle
Package lambda-bundle
Short Description Run symfony code via AWS Lambda
License MIT
Informations about the package lambda-bundle
DayspringLambdaBundle - Run Symfony on Lambda
This bundle provides tooling for using Lambda to run Symfony code. Your application will run as a custom Lambda runtime
This is based on bref's console example bootstrap script and removes the need to use only console commands. It also boots the Symfony kernel once for the lifetime of the Lambda worker.
bref provides a Lambda runtime API client implementation. This handles communication with the Lambda runtime API
Using this bundle
1. Add this bundle to your Symfony project.
- Add this package to your project by running
composer require dayspring-tech/lambda-bundle
- Package your project in a docker image.
- Add
Bootstrap/service.php
to your image as/var/run/bootstrap
, and make it executable. This is the foundation of your custom Lambda runtime.
2. Create a class that implements LambdaHandlerServiceInterface
- Create a class that implements
LambdaHandlerServiceInterface
and register it with Symfony's dependency injection container. It should be marked as public so it can be fetched by name. - Implement the
handle()
function- The custom runtime will call the
handle()
function for each Lambda event, passing the event object as the$event
argument. - Lambda context information will be provided via the
$context
argument. - The custom runtime will provide an
OutputInterface
object with which you can provide any output that should be returned from the Lambda function.
- The custom runtime will call the
3. Register a Lambda function
- Create a Lambda function in AWS using your docker image. Set the Lambda command to the service name.
Background on the custom Lambda runtimes and the Lambda Runtime API
If there's a /var/run/bootstrap
file in your docker image, Lambda will execute it. This is your custom runtime.
- The Lambda runtime API exposes three APIs. Your custom runtime should call the
/next
API to request the next event. - Your custom runtime should execute code to handle the event. For LambdaBundle, this is calling the
handle()
function on theLambdaHandlerServiceInterface
specified via the Lambda function's command parameter. - If successful, your custom runtime calls the
/response
API and POSTs the function's response. - On an error, your custom runtime calls the
/error
API with details of the error.
See also:
- https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html
- https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html
Provided Handlers
The following handlers are provided as examples or common implementations of LambdaHandlerServiceInterface
EchoLambdaHandlerService
This handler will echo the event body
value to Lambda's output. Useful for testing your container and Lambda configuration.
ServiceFunctionHandlerService
This handler can handle lambda events and call any public function on any service available via Symfony's dependency injection container.
It expects a lambda event in the format:
serviceName
: any service identifier valid withContainer::get()
. This will likely be a service class name.function
: the function nameargs
: an array of arguments to the function
SqsServiceFunctionHandlerService
This handler does the same thing as ServiceFunctionHandlerService
but for messages sent via SQS
It expects payloads to be sent via SQS instead of directly to Lambda.
Other implementation possibilities
- API Gateway - Configure a Lambda integration with API Gateway and use Symfony to handle API requests
- SNS - Subscribe Lambda to a SNS topic and handle messages from SNS
- Custom events - Configure Lambda as a task within Step Functions
All versions of lambda-bundle with dependencies
ext-json Version *
symfony/dotenv Version ^4.4|^5.0
symfony/framework-bundle Version ^4.4|^5.0
symfony/yaml Version ^4.4|^5.0
sensio/framework-extra-bundle Version ^5.0.1
bref/bref Version ^1.7