I started by using the docs, and leaned into this for the Laravel specifics:
https://bref.sh/docs/frameworks/laravel.html
I have successfully setup bref+laravel using a hard-coded string value in place of the $_ENV['APP_STORAGE] value normally added to /bootstrap/app.php (see below for contents).
It appears that my php-fpm process is not getting the environment propped. In my template.yaml I am using the latest layers. Specifically for fpm arn:aws:lambda:us-west-2:209497400698:layer:php-73-fpm:3
It looks like this was a problem back in #161 but that looked to be resolved and closed.
To best illustrate the problem and solution, this is the top part of my /bootstrap/app.php with comments on the $app->useStoragePath(...) patch the docs have me apply:
<?php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
/*
* Allow overriding the storage path in production using an environment variable.
*/
// Per the docs (this does not work):
// $app->useStoragePath($_ENV['APP_STORAGE'] ?? $app->storagePath());
// When I dd($_ENV['APP_STORAGE']) I get a null, when I dd($_ENV) I get an empty []
// My temporary fix that I enable when I'm ready to deploy to AWS
$app->useStoragePath('/tmp' ?? $app->storagePath());
Just in case it is needed, this is my template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Environment:
Variables:
# Laravel environment variables
APP_STORAGE: '/tmp'
Resources:
Website:
Type: AWS::Serverless::Function
Properties:
FunctionName: 'laravel-website'
CodeUri: .
Handler: public/index.php
Timeout: 30 # in seconds (API Gateway has a timeout of 30 seconds)
Runtime: provided
Layers:
- 'arn:aws:lambda:us-west-2:209497400698:layer:php-73-fpm:3'
Events:
# The function will match all HTTP URLs
HttpRoot:
Type: Api
Properties:
Path: /
Method: ANY
HttpSubPaths:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
Artisan:
Type: AWS::Serverless::Function
Properties:
FunctionName: 'laravel-artisan'
CodeUri: .
Handler: artisan
Timeout: 120
Runtime: provided
Layers:
# PHP runtime
- 'arn:aws:lambda:us-west-2:209497400698:layer:php-73:3'
# Console layer
- 'arn:aws:lambda:us-west-2:209497400698:layer:console:3'
Outputs:
DemoHttpApi:
Description: 'URL of our function in the *Prod* environment'
Value: !Sub 'https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/'
I use this script to preflight and then deploy my code:
#!/usr/bin/env bash
# Install Composer dependencies optimized for production
composer install --optimize-autoloader --no-dev
# Perform extra tasks for your framework of choice
# (e.g. generate the framework cache)
php artisan config:clear
# Package
sam package --output-template-file .stack.yaml --s3-bucket this-is-a-test-bref-laravel-stack
# Deploy
sam deploy --template-file .stack.yaml --capabilities CAPABILITY_IAM --stack-name this-is-a-test-bref-laravel-stack
Thank you, I have reproduced and identified the problem, sorry about that.
See #291 for a pull request and a current work in progress.
@lhilton should be all good with the last Bref version and the last runtime versions (don't forget to update the runtime versions!): https://github.com/mnapoli/bref/releases/tag/0.3.7