Laravel Vapor. Migrating existing app to serverless. Easy or not?

Ivan Kolodii
5 min readMar 14, 2021
Laravel vapor

App autoscaling is not a trivial task as it might look. I was really excited when I read about Vapor. I would like to share my experience of playing with this great tool.

Project size

Our project is nearly 650Mb and Lambda has limitations of 250Mb unzipped.

We had a few binaries in our composer dependencies. I tried to remove them but it doesn’t help.

Want to read this story later? Save it in Journal.

Also removed all dev dependencies. Make sure that you don’t use any PHPUnit functions in your code. For example: assert() etc.

Next, I found out that vapor supports Lambda layers via docker. It has a limit of up to 10Gb per layer.

That helped. All your need to do is only add this line:

runtime: docker

And create a docker file associated with it. You can use the command

vapor env my-environment — docker

Building assets

We use docker containers for the local development and a simple composer install command won’t work locally.

You have to run a command via docker-compose exec.

It’s not a big problem but still, you need to be ready to adjust deployment scripts.

Working directories

We are using a storage directory to save some files, configurations. The storage directory is not available via Lambda or I’m missing something.

Laravel passport

Lambda functions don’t work properly with storage as every request goes to the new container.

You can use EFS but we tried to avoid it as it has limitations and pricing can be high.

Passport requires certs but they can be stored in the env. So we put them under Secrets. Read more about it here

Ivan Kolodii

Recommended from Medium