Download the PHP package runtime/bref without Composer
On this page you can find all versions of the php package runtime/bref. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package bref
Bref Runtime
Deploy an application with AWS Lambda using Bref.
We support all kinds of applications. See the following sections for details.
- Installation and usage
- Symfony application
- Laravel application
- PSR-15 application
- Console application
- PSR-11 container application
- Invoke handlers locally
- Simplify serverless.yml
- Typed handlers
- Symfony Messenger integration
If you are new to the Symfony Runtime component, read more in the main readme.
Installation
To get started, we need a serverless.yml
file in our projects root. We also
use the ./vendor/runtime/bref-layer
plugin. Now we can tell AWS that we want
to use a "layer" called ${runtime-bref:php-80}
to run our application on.
Next we need to define the environment variable APP_RUNTIME
so the Runtime component
knows what runtime to use.
That is really it!
We use this file for all kinds of applications. The only thing we change in the
events
. Imagine that we want to listen to changes to S3 or new SQS messages.
Or we could let this function to be invoked by another application in our system
using a Bref\Event\Handler
.
Symfony application
You need some extra features from Bref. Install it with
Use the standard Symfony 5.3+ public/index.php
.
There is nothing special you need to do.
Here is an example application. With this runtime you may use the exact same application for in local development and in production.
Laravel application
You need some extra features from Bref. Install it with
To run a Laravel application, you need to update your front controller to look similar to this:
Now you are up and running on AWS Lambda!
See runtime/laravel
on how to run
this locally.
PSR-15 application
You need some extra features from Bref. Install it with
Bref is using nyholm/psr7
to provide a PSR-7
and PSR-15 experience. See runtime/psr-nyholm
how to run your application locally.
The following code is an example PSR-15 application with the Runtime component. If it works locally it will also with on AWS Lambda.
Console application
Use the standard Symfony 5.3+ bin/console
.
PSR-11 Container
The PSR-11 container is great. It really shines in internal microservices where
you dont have to deal with HTTP or security. Your application just call your microservice
using an AWS Lambda api client (ie aws/aws-sdk-php
or async-aws/lambda
).
It is also great for reacting to S3 or SQS events.
The first thing we need is a file that returns a PSR-11 container. See below for an example for Symfony.
Now we write a class/service that implements Bref\Event\Handler
.
Now we need to update serverless.yml to say "Use bin/container.php to get the container and then load service App\Lambda\HelloWorld".
When this is deployed it can be invoked by
Invoke handlers locally
Using a service from the container makes the handlers very simple to unit test. However, if you are lazy, you may want to invoke them locally from CLI.
Run the following command to invoke the App\Lambda\HelloWorld
service.
If your service expects some event data, add it as a JSON string or a path to a file containing JSON.
Simplify serverless.yml
The syntax handler: bin/container.php:App\Lambda\HelloWorld
might be a bit weird to write,
but you may add an environment variable called FALLBACK_CONTAINER_FILE
which
includes the file to where we can get the PSR-11 container. This may help the
serverless.yml file to read more natually.
Typed handlers
To better integrate with different AWS events, one can use "typed handlers".
These are classes that implements Bref\Event\Handler
and provides some helper
methods or classes.
To use them, you need to install Bref:
We use the same PSR-11 configuration from above and write custom handler like:
Read more about different typed handlers at Bref's documentation.
Symfony Messenger integration
Similar to the typed handlers above, if you use bref/symfony-messenger
you may also want to define a worker function.
All versions of bref with dependencies
ext-json Version *
ext-sockets Version *
clue/arguments Version ^2.1
psr/http-server-handler Version ^1.0
riverline/multipart-parser Version ^2.0.9
runtime/bref-layer Version ^1.3
symfony/runtime Version ^5.4 || ^6.0 || ^7.0