Sidecar packages, deploys, and executes AWS Lambda functions from your Laravel application.

Published on by

Sidecar packages, deploys, and executes AWS Lambda functions from your Laravel application. image

Sidecar is a package by the Hammerstone team that takes the pain out of the packaging, deploying, and executing of AWS Lambda functions from your Laravel application.

Sidecar supports both Laravel 7 and 8 and requires PHP 7.2 or newer.

Laravel Vapor brought the power of serverless to Laravel. Using Vapor, you can run your plain ol' Laravel apps on a serverless platform and get incredible speed, security, and reliability.

Sidecar brings the ease of Vapor to non-PHP functions. Common use cases could be taking screenshots with headless Chrome, running FFmpeg, doing some data work with Python, generating images, or rendering your Javascript frontend server-side.

Or maybe you want to run a single Ruby script without configuring Ruby on your server. Or Java. Or even Powershell for some reason?

You can use any of the runtimes supported by Lambda:

  • Node.js 14
  • Node.js 12
  • Node.js 10
  • Python 3.8
  • Python 3.7
  • Python 3.6
  • Python 2.7
  • Ruby 2.7
  • Ruby 2.5
  • Java 11
  • Java 8
  • Go 1.x
  • .NET Core 3.1
  • .NET Core 2.1

Sidecar comes with a sidecar:configure command that interactively walks you through setting up the correct permissions in AWS so that you don't have to mess around in the IAM UI.

Once you have your credentials configured, making your first Lambda requires only two things:

  • A PHP class
  • The files you want to be deployed to Lambda

Let's assume we're going to use Node to generate an image. Your function class could look like this:

namespace App\Sidecar;
 
use Hammerstone\Sidecar\LambdaFunction;
 
class GenerateImage extends LambdaFunction
{
public function handler()
{
// Define your handler function.
// (Javascript file + export name.)
return 'resources/lambda/image.handler';
}
 
public function package()
{
// All files and folders needed for the function.
// In this case some JS files and some fonts.
return [
'resources/lambda',
'resources/fonts',
];
}
}

With your function configured, you can deploy and activate it with a simple command:

php artisan sidecar:deploy --activate

The above command creates your Lambda function on AWS and prepares it for use.

You can execute this function anywhere in your Laravel application simply by calling execute on the class, passing any data you want to the Lambda function.

$image = GenerateImage::execute([
'text' => 'This image was generated on Lambda!'
]);

This article is a very brief overview of what Sidecar can do. Sidecar also handles:

  • Separate environments
  • Async execution
  • Multiple, concurrent async execution
  • Configurable memory, timeout, and runtime per function
  • Separate deploy and activate steps for zero downtime or version drift
  • Retrieving logs and timings per execution
  • Returning Lambda execution results directly to the browser as Laravel responses

To read the full documentation see https://hammerstone.dev/sidecar/docs or visit the GitHub repository at https://github.com/hammerstonedev/sidecar.

Please note that this is a v0.1.0 release. Issues are being addressed quickly, and features are being added as they move towards a 1.0 release. Feel free to reach out to the author directly on Twitter at twitter.com/aarondfrancis.

Aaron Francis photo

Writing and tweeting about building products + Laravel.

Working on torchlight.dev & hammerstone.dev.

Dad to boy/girl twins.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Add Comments to your Laravel Application with the Commenter Package image

Add Comments to your Laravel Application with the Commenter Package

Read article
Laravel Advanced String Package image

Laravel Advanced String Package

Read article
Take the Annual State of Laravel 2024 Survey image

Take the Annual State of Laravel 2024 Survey

Read article
Upload Files Using Filepond in Livewire Components image

Upload Files Using Filepond in Livewire Components

Read article
The Best Laravel Tutorials and Resources for Developers image

The Best Laravel Tutorials and Resources for Developers

Read article
Introducing Built with Laravel image

Introducing Built with Laravel

Read article