Laravel Vapor: Serverless Laravel on AWS
Serverless Laravel
Laravel Vapor brings serverless deployment to Laravel, running your application on AWS Lambda. No servers to manage, automatic scaling, and pay-per-request pricing make it attractive for many workloads.
Getting Started
composer require laravel/vapor-core --update-with-dependencies
npm install -g @laravel/vapor-cli
vapor login
vapor.yml Configuration
id: my-app
name: my-app
environments:
production:
memory: 1024
cli-memory: 512
runtime: php-8.3:al2
build:
- 'composer install --no-dev'
- 'npm ci && npm run build'
deploy:
- 'php artisan migrate --force'
queues:
- default
scheduler: true
database: my-database
cache: my-cache
Deployment
vapor deploy production
Understanding Lambda Constraints
Lambda functions have limitations to consider:
- 15-minute maximum execution time
- 512MB-10GB memory
- Stateless execution (no persistent connections)
- Cold starts on idle functions
Handling File Uploads
Lambda has a 6MB request payload limit. Use signed uploads for larger files:
// Generate signed URL
$url = Storage::temporaryUploadUrl(
'uploads/' . Str::uuid() . '.pdf',
now()->addMinutes(5)
);
// Client uploads directly to S3
// Then notifies your app of the upload location
Database Connections
Use RDS Proxy to manage database connections efficiently with Lambda's scaling behavior:
// vapor.yml
environments:
production:
database: my-db
database-proxy: true
Queues with SQS
// vapor.yml
environments:
production:
queues:
- default: 50 # Max concurrent jobs
- emails: 10
queue-memory: 1024
Reducing Cold Starts
// vapor.yml
environments:
production:
warm: 10 # Keep 10 warm instances
Monitoring
Vapor provides a dashboard for monitoring deployments, queue health, and function metrics. Integrate with CloudWatch for deeper insights.
Cost Optimization
Lambda charges per invocation and GB-second of compute. Optimize by:
- Right-sizing memory (affects CPU)
- Minimizing cold starts with warming
- Using queues for background work
- Caching aggressively
Conclusion
Vapor makes serverless Laravel deployment straightforward. For applications with variable traffic or where you want to avoid server management, it's an excellent choice. Understand the constraints and design accordingly.
Related Articles
Need Help With Your Project?
I respond to all inquiries within 24 hours. Let's discuss how I can help build your production-ready system.
Get In Touch