Download the PHP package stechstudio/laravel-bref-bridge without Composer
On this page you can find all versions of the php package stechstudio/laravel-bref-bridge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-bref-bridge
bref, the Laravel Way
If you were looking for a way to easily deploy your Laravel project to AWS Lambda, you are in the correct place!
Building on the excellent bref project, we provide a simple and painless entry to the world of Serverless Laravel in AWS.
Installation
Assuming your are in existing Laravel project, let's install the bridge via Composer:
There is a route, config file, and AWS SAM template that needs to be published.
Configuration
TL;DR
Edit .env
AWS
You will need an S3 bucket to send the Function Package to in order for Cloudformation to consume it. Either use an existing bucket, or create a new one. You can easily create a new one with the AWS CLI like this.
.env
New edit your .env
file and add:
Region Layers
While there is a default us-east-1 layer configured for you, it is best to reference https://bref.sh/docs/runtimes/ and find the ARN for the latest bref layer in the region you intend to deploy your lambda function.
Note that when you select the base layer, we require one of the php-??-fpm layers. Neither the php-?? nor the console layer types are compatible with this bridge.
Ensure that the region and the layer match, like so:
SQS Job Queue
We will report the created default Job Queue after deployment. The Function will be configured to receive events from it as well as write to it. This means that when you dispatch a job to the default queue, it will trigger the same lambda function to handle the job.
SAM Template
You will now find template.yml
in your base directory and you can open it up, review it, edit, or just ignore it for now. When you are done, lets run the configuration command. This will generate a final template based on your .env
file. If you modify anything in the .env
you should run this command again to update the template.
Lambda Routes
What are lambda routes? Glad you asked! Many people only concern themselves with events from API Gateway and/or AWS SQS that trigger their Lambda Jobs. However, there are a whole slew of events that might be configured to trigger your lambda function.
We have a router implemented for Laravel that makes it trivial for your application to consume and react to events from multiple triggers, all in a single Lambda Function. We use the AWS Events Package to transform the incoming events into the appropriate PHP Object, and then determine what controller to send that event too.
API Gateway
All API Gateway Proxy Request Events are hardwired to be treated as any normal web request. The event will be transformed into an HTTP Request and passed off to PHP-FPM just like nginx or apache would. The result will then be transformed back into the appropriate API Gateway Proxy Response and sent back to the Gateway. All you have to do for this scenario is write your HTTP routes and controllers the same as you would for any traditional Laravel app and, if we did our job correctly, it should just work!
The Other Events
Apart from API Gateway, we currently support routing for all (sixteen) of the other possible events. If you are not using any other events, you can simply ignore this section. However, for those who venture beyond the API Gateway, lets publish the example routes file.
This will result in a routes/lambda.example.php
being placed in your project. You will need to manually rename it to routes/lambda.php
before it will be used. When you look at it you will notice that it follows the same paradigm as the HTTP Routes. You may either map a callback or map a Lambda Controller.
The router will then ensure that when an event of the type you are routing shows up, it gets passed on to the appropriate callable
to handle the event. You simply need to return an array
when you are done. To help you with testing the routing of various events, here are some samples.
AWS CloudFormation Create Request Sample Event
Amazon SES Email Receiving Sample Event
Scheduled Event Sample Event
Amazon CloudWatch Logs Sample Event
Amazon SNS Sample Event
Amazon DynamoDB Update Sample Event
Amazon Cognito Sync Trigger Sample Event
Amazon Kinesis Data Streams Sample Event
Amazon S3 Put Sample Event
Amazon S3 Delete Sample Event
Amazon Lex Sample Event
Amazon SQS Event
CloudFront Event
AWS Config Event
AWS IoT Button Event
Kinesis Data Firehose Event
After you publish your package to lambda, you can head over to the AWS console to copy/paste the various samples here into the tests and run them manually. You could also do that from the AWS CLI if want to test from there.
Packaging & Deploying
We have made this as trivial as possible.
This will generate a storage/latest.zip
package of your current code. There will be no dev packages from composer, so if you want those packages you will need to move them into the required stanza.
After a few moments, the job will finish and you can head over to the AWS Console to check out your new Lambda Job.
That was it, Congratulations!
Configuration Options
The config/bref.php
file holds our configuration options for us. This is a high level overview of the available settings. Please see comments in the file itself for more detail and defaults.
- name - This value is the name of your Lambda. This value is used when the framework needs to generate the lambda function names.
- description - This value is the description of your Lambda. This value is used when the framework needs to generate the lambda function descriptions.
- region - This value is the region of your Lambda. This value is used when the framework needs to generate the lambda function regions.
- timeout - This value is the timeout, in seconds, to configure the lambda function for. The API Gateway timeout is 30 seconds, so that is our default. The maximum timeout is 900 seconds (15 minutes).
- memory_size - The amount of memory that your function has access to. Increasing the function's memory also increases it's CPU allocation. The default value is 128 MB and the maximum value is 3,008 MB. The value must be an integer multiple of 64 MB.
- layers - A list of function layers to add to the function's execution environment. Specify each layer by ARN, including the version, in the order they should be layered, with a maximum of five layers.
- keep - The number of latest (zip) packages to keep on the filesystem.
- sqs - Lambda consumption of job queues gets configured here. Publishing jobs to queues still works as normal, So no changes there. Just update the .env
- packaging - This array configures the files that should be ignored when packaging your application, as well as identifying executable files.
- env - This array configures environment variables that are passed in for function code, as well as listing those that are ignored.
.env Variables
The following .env
variables are available to be used. Reference the config/bref.php
for more details.
- BREF_NAME - This value is the name of your Lambda. This value is used when the framework needs to generate the lambda function names.
- BREF_DESCRIPTION - This value is the description of your Lambda. This value is used when the framework needs to generate the lambda function descriptions.
- BREF_DEFAULT_REGION - This value is the region of your Lambda. This value is used when the framework needs to generate the lambda function regions.
- BREF_FUNCTION_TIMEOUT - This value is the timeout, in seconds, to configure the lambda function for. The API Gateway timeout is 30 seconds, so that is our default. The maximum timeout is 900 seconds (15 minutes).
- BREF_FUNCTION_MEMORY_SIZE -The amount of memory that your function has access to. Increasing the function's memory also increases it's CPU allocation. The default value is 128 MB and the maximum value is 3,008 MB. The value must be an integer multiple of 64 MB.
- BREF_FUNCTION_LAYER_1 - The ARN, including version, of the first layer. This will override the default layer.
- BREF_FUNCTION_LAYER_2 - The ARN, including version, of the second layer, if used.
- BREF_FUNCTION_LAYER_3 - The ARN, including version, of the third layer, if used.
- BREF_FUNCTION_LAYER_4 - The ARN, including version, of the fourth layer, if used.
- BREF_FUNCTION_LAYER_5 - The ARN, including version, of the fifth layer, if used.
- BREF_PACKAGE_KEEP - The number of latest (zip) packages to keep on the filesystem.
- BREF_APP_STORAGE - Where the laravel app storage should be. Defaults to
/tmp/storage
. - BREF_LOG_CHANNEL - How to handle logging in lambda. Defaults to
stderr
. - BREF_CACHE_DRIVER - The cache driver to use in Lambda. Defaults to
file
. - BREF_SESSION_DRIVER - The Session driver to use in Lambda. Defaults to
array
. - BREF_QUEUE_CONNECTION - The queue connection to use in Lambda. Defaults to
sqs
.
Enable an Extension
If you would like to enable an extension, of simply modify the php.ini directives, you can do so by creating a ./storage/php/conf.d
directory.
Anything you place in that directory will get packaged to end up in /var/task/php/config.d
which is the default for bref.
For example, to enable pdo_mysql
, which comes in the base bref layer, just create a ./storage/php/conf.d/mysql.ini
file like so:
See: https://bref.sh/docs/environment/php.html#customizing-phpini https://bref.sh/docs/environment/php.html#extensions-installed-but-disabled-by-default
All versions of laravel-bref-bridge with dependencies
ext-curl Version *
ext-json Version *
ext-pcre Version *
ext-iconv Version *
ext-openssl Version *
ext-fileinfo Version *
ext-mbstring Version *
ext-simplexml Version *
ext-tokenizer Version *
ext-parallel Version *
symfony/yaml Version ^4.2
bref/bref Version ^0.3.4
illuminate/http Version ^6.0|^7.0
illuminate/support Version ^6.0|^7.0
laravel/framework Version ^6.0|^7.0
psr/http-server-handler Version ^1.0
stechstudio/aws-events Version ^1.0
symfony/psr-http-message-bridge Version ^1.1
gisostallenberg/file-permission-calculator Version ^1.0