laravel/vapor-core
Core runtime and service providers that power Laravel Vapor deployments on AWS Lambda. Helps Laravel apps run smoothly in serverless environments, integrating with SQS, databases, Redis, networking, CloudFront, and other AWS services used by Vapor.
Installation:
Add the package to your composer.json:
composer require laravel/vapor-core
Ensure your Laravel app is v10+ (preferably v13 for full Symfony 8 support).
Environment Setup:
Set VAPOR_ENV in your .env:
VAPOR_ENV=production
This overrides APP_ENV in serverless contexts.
First Use Case: Check if your app is running on Vapor:
use Illuminate\Support\Facades\App;
if (App::runningOnVapor()) {
// Vapor-specific logic (e.g., optimized caching, SQS queues)
}
Verify Runtime: Test Lambda event handling by triggering a route or queue job. The package auto-configures request parsing (API Gateway, SQS, etc.).
APIGatewayProxyRequest into Laravel’s $request object.
// Access API Gateway metadata (e.g., request ID)
$requestId = request()->header('X-Amzn-Trace-Id');
Vapor::event() to inspect incoming SQS messages:
use Laravel\Vapor\Vapor;
$event = Vapor::event();
if ($event->isSqs()) {
$body = $event->body(); // Decoded SQS payload
}
if (App::runningInConsole() && App::runningOnVapor()) {
// Run Vapor-specific Artisan commands (e.g., `vapor:deploy`)
}
config('vapor.*.key') for Vapor-only settings (e.g., SQS queue names).dispatch(new ProcessPayment)->onVaporQueue('payments');
v2.37.2+).use Laravel\Vapor\Console\DynamicCliHandler;
DynamicCliHandler::macro('custom', function ($input, $output) {
// Custom CLI logic
});
use Laravel\Vapor\Vapor;
$context = Vapor::context();
$functionName = $context->functionName; // e.g., "app-1234567890"
if (App::runningOnVapor()) {
Log::debug('Vapor-specific debug info');
}
config('database.connections.mysql.serverless') for Vapor’s serverless database proxies.filesystems.disks.s3 with driver: 's3' and endpoint: 'https://s3.amazonaws.com' (or your S3-compatible endpoint).v2.32.2+ for Octane compatibility:
use Laravel\Octane\Facades\Octane;
Octane::streaming(function () {
// Streamed response logic
});
vapor:queue to run workers in Vapor:
php artisan vapor:queue --queue=high
Vapor\Events\JobProcessed:
event(new Vapor\Events\JobProcessed($job));
if (Vapor::event()->isLambda()) {
$detail = Vapor::event()->detail(); // Custom event data
}
Environment Confusion:
APP_ENV may not reflect Vapor’s environment if VAPOR_ENV is misconfigured.App::runningOnVapor() to check context:
if (App::runningOnVapor() && App::environment('staging')) {
// Vapor staging logic
}
PDO "Server Gone Away" Errors:
v2.43.3).DB::reconnect() or configure wait_timeout in your RDS proxy.Multipart Form Data:
v2.37.9).v2.37.9+ or manually parse $request->all().Octane + Vapor:
v2.37.8).v2.37.8+ or use session()->put() explicitly.S3-Compatible Storage:
v2.38.0+ and configure endpoint explicitly:
'disks' => [
's3' => [
'driver' => 's3',
'endpoint' => env('S3_ENDPOINT', 'https://s3.amazonaws.com'),
],
],
Cold Starts:
boot() can delay cold starts.if (!App::runningOnVapor()) {
// Heavy boot logic (e.g., caching)
}
Lambda Context:
dd(Vapor::context()->toArray());
functionName, invokedFunctionArn, and awsRequestId.Event Inspection:
Log::debug('Raw event:', Vapor::event()->raw());
Environment Detection:
dd([
'runningOnVapor' => App::runningOnVapor(),
'environment' => App::environment(),
'vaporEnv' => env('VAPOR_ENV'),
]);
Queue Jobs:
php artisan vapor:queue:work --queue=critical --timeout=30
Custom Event Handlers:
Laravel\Vapor\Events\VaporEvent to handle custom Lambda/SQS events:
class CustomEvent extends VaporEvent
{
public function isCustom(): bool
{
return $this->raw['detail-type'] === 'custom.event';
}
}
Dynamic CLI Handlers:
DynamicCliHandler::extend('custom:command', function ($input, $output) {
$output->writeln('Running custom command on Vapor!');
});
Service Provider Overrides:
VaporServiceProvider for custom logic:
app()->register(\App\Providers\CustomVaporServiceProvider::class);
Request Parsing:
use Laravel\Vapor\Http\RequestParser;
RequestParser::macro('custom', function ($request) {
// Custom parsing logic
});
VAPOR_ENV Override:
VAPOR_ENV over APP_ENV in serverless contexts. Set it in your Vapor environment variables:
VAPOR_ENV=staging
Queue Configuration:
vapor-<queue-name>. Override in config/queue.php:
'connections' => [
'vapor' => [
'driver' => 'sqs',
'queue' => env('SQS_QUEUE', 'vapor-default'),
How can I help you explore Laravel packages today?