hammerstone/sidecar
Sidecar lets Laravel package, deploy, and invoke AWS Lambda functions directly from your app. Define a simple PHP class plus the files to ship, choose any supported runtime (Node, Python, Java, .NET, Ruby, or OS-only), and execute from PHP.
sidecar.php). Minimal boilerplate for deployment/execution.sidecar:deploy, sidecar:warm) integrate naturally with GitHub Actions, CircleCI, or Laravel Forge.| Risk Area | Mitigation Strategy |
|---|---|
| AWS Costs | Lambda cold starts and idle functions can incur costs. Mitigate with provisioned concurrency or warming strategies. |
| Runtime Lock-In | Breaking changes (e.g., runtime deprecations like Node.js 16) may require updates. Monitor changelog for compatibility. |
| Error Handling | Lambda timeouts/memory limits may crash PHP. Use try-catch with SettledResult and implement retry logic. |
| Security | Lambda execution roles must be scoped. Sidecar removes default SES/SQS/DynamoDB permissions by default (good practice). |
| State Management | Lambda is stateless. Use S3, DynamoDB, or ElastiCache for shared data. |
| Vendor Lock-In | AWS-specific. If multi-cloud is a requirement, evaluate alternatives like Knative or OpenFaaS. |
| Phase | Action Items |
|---|---|
| Assessment | Audit existing long-running PHP scripts or external API calls to identify candidates for Lambda migration. |
| Pilot | Start with non-critical functions (e.g., image generation, PDF creation). Use Sidecar’s execute() in a feature branch before merging to main. |
| Infrastructure | Set up AWS IAM roles with minimal permissions (Sidecar handles this via sidecar:configure). Ensure VPC (if needed) and S3 buckets for deployment artifacts are configured. |
| CI/CD Integration | Add Sidecar commands to deployment pipeline: |
# Example GitHub Actions step
- name: Deploy Lambda Functions
run: php artisan sidecar:deploy --activate --pre-warm
| Monitoring | Integrate CloudWatch Logs with Laravel’s logging (e.g., monolog). Use SettledResult to capture Lambda errors in PHP. |
| Rollout | Deploy to staging first, then canary release to production (e.g., route traffic via Laravel’s queue:work). |
Dispatch(new ProcessImage($imageId))->onQueue('lambda');
LambdaFunction or using local Lambda emulation (e.g., Docker + SAM).sidecar.env config to avoid namespace collisions in shared AWS accounts.php artisan sidecar:configure to set up IAM roles.LambdaFunction classes in app/Sidecar/ (e.g., OgImage.php).resources/lambda/image.js).php artisan sidecar:deploy --dry-run.php artisan sidecar:deploy --activate --pre-warm.$result = OgImage::execute(['text' => 'Hello']);
sidecar:sweep to clean up old versions.// Explicitly set runtime to avoid auto-updates
public function runtime(): string { return 'nodejs20.x'; }
config:cache) to avoid runtime config reloads..env (e.g., SIDECAR_RUNTIME_MEMORY=512).SettledResult::errorAsString().sidecar:logs to stream CloudWatch logs:
php artisan sidecar:logs OgImage
| Issue | Resolution |
|---|---|
| Cold Starts | Use --pre-warm in deploy or set provisioned concurrency in AWS Console. |
| Permission Denied | Re-run sidecar:configure or check IAM policies. |
| Timeout Errors | Increase Lambda timeout or optimize runtime code. |
| Deployment Failures | Check S3 bucket permissions or Lambda quotas. |
| Runtime Mismatch | Explicitly set runtime() in LambdaFunction class. |
How can I help you explore Laravel packages today?