Serverless Laravel
Production Showcase Source Code
The why, the how and the what
Use this repository when you want to automate creating a serverless Laravel environment.
It uses AWS SAM to create the AWS resources including:
- Route 53 entries && SSL certificates
- CloudFront
- API Gateway for Lambda & Artisan
- Assets S3 bucket for static files
- Storage S3 bucket for internal files
It also makes use of GitHub actions for CI/CD automation.
Setup
- Fork rdok/serverless-laravel template
- Update the repository secrets with AWS credentials & others.
- Update environment variables of artisan.yml & deploy.yml.
- The IAM policies required for the CI/CD user are outside the scope of this post. However, you can reference the automated policies for the showcase here.
- Deploy using Deploy Github action.
- Run artisan commands using the Artisan GitHub action.
Pre-requisites
To automate the creation of the subdomain & it’s certificate.
An existing base domain & wild card certificate.
Future additions
The following Laravel features will be supported in future posts:
- Aurora serverless MySQL database
- Broadcasting through SNS
- Job dispatching through SQS
- Scheduling through additional Lambda
Environment variables
Instruct Laravel how to load static assets & access storage bucket:
Domain Certificate
CloudFront only supports ACM certificates in the US East (N. Virginia) Region. As such, a separate stack is created in the us-east-1
region.
Storage
Instruct Laravel to properly get AWS credentials by adding the AWS session token:
CI/CD
CI/CD uses AWS SAM to build & deploy AWS resources: