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.

Curotec logo

Curotec

Hire the top Latin American Laravel talent. Flexible engagements, budget optimized, and quality engineering.

Curotec
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
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
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Join the Mastering Laravel community logo

Join the Mastering Laravel community

Connect with experienced developers in a friendly, noise-free environment. Get insights, share ideas, and find support for your coding challenges. Join us today and elevate your Laravel skills!

Join the Mastering Laravel community
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
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 Multi-tenant 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
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 →
Connecting Laravel Socialite with Google Client PHP Library image

Connecting Laravel Socialite with Google Client PHP Library

Read article
Create Self-Contained PHP Executables with PHPacker image

Create Self-Contained PHP Executables with PHPacker

Read article
String Manipulation with Laravel's remove Method image

String Manipulation with Laravel's remove Method

Read article
Stargazing in Your Laravel App with Intervention Zodiac image

Stargazing in Your Laravel App with Intervention Zodiac

Read article
Simple Cookie Consent Packge for Laravel image

Simple Cookie Consent Packge for Laravel

Read article
Leveraging Laravel's Conditional Ping Methods for Task Monitoring image

Leveraging Laravel's Conditional Ping Methods for Task Monitoring

Read article