This application contains an example of how to deploy Laravel 8.x as a lambda function in aws. The resources that you will create in your aws account after run serverless deploy are the following.
- Laravel Function.
- Artisan Function.
- HTTP entry point using AWS API Gateway.
Prerequisites
- AWS account and a user with programmatic access via API with the necessary permissions.
- Composer
- Node.js
Get started
- Clone the repository and configure it.
# Clone this project
git clone --depth 1 https://github.com/gregorip02/laravel-lambda.git
cd laravel-lambda
# Setup environment file
cp .env.example .env
# Generate an application key and copy it to your environment variables file.
echo "base64:$(openssl rand -base64 32)"
# Paste the output in .env file
# APP_KEY=base64:e4IiYMsTe+n+NZMjgPZyCL4kKWJ2y0itnYGqk2ZBJ7c=- Configure your serverless credentials using:
npx serverless config credentials --provider aws --key YOUR-AWS-KEY --secret YOUR-AWS-SECRET -o- Deploy.
By default the deployment of the app is in production mode, before executing the
deployment it is optimized to add caching to the aws lambda execution environment
by adding cache to the configuration and paths of your application.
See app/Console/Commands/ServerlessOptimizeCommand.php.
make deployYou can find more documentation on the official brefphp page.
Run
npx serverless removeto destroy the stack.
TODO
- Add support for SQS.
- Add support for Elastic Cache.
- Add support for Schedule Commands.
On this page
Languages
PHP81.7%Blade17.0%Shell0.8%Makefile0.5%
Contributors
Created August 22, 2021
Updated August 23, 2021