I am a bit confused by the fact that deploying a lambda means building (or packaging) it in the project’s directory.
For example, in production I need to have a file in the lambda. I wrote a plugin that generates the file when the lambda is packaged (thanks to a hook).
But now every time I deploy the file is generated in the project’s directory!
That doesn’t sound so bad, but I’m working on whole PHP support and I’m writing caches for production, and after each deploy the app is basically broken in the dev environment because caches are made for the prod environment.
Is there a way to make serverless prepare the application for packaging in another folder? (and I’m not talking about generating the zip file in another folder!)
Thanks! However that is not related to what I want to do.
I am deploying a PHP lambda. So in the deploy step, I download the PHP binary and put it in the project directory (thanks to a plugin). serverless deploy then uploads that and it works.
The problem is I have this PHP binary in my project now…
And I have the same problem with many files : e.g. I generate cache files, optimized autoloader, etc. And all those files are left in my project (i.e. on my PC) after serverless deploy.
So I would like to prepare the zip file in a separate directory (even a temp directory is fine).
Only for package? So option --package is what you are looking for?
$ sls package --help
Plugin: Package
package ....................... Packages a Serverless service
--stage / -s ....................... Stage of the service
--region / -r ...................... Region of the service
--package / -p ..................... Output path for the package
I do not want to exclude it, the PHP binary should be deployed into the lambda.
Here is another way to explain it:
Expected files:
# Locally
handler.js
test.php
# In the lambda
handler.js
test.php
bin/php
Actual files:
# Locally
handler.js
test.php
bin/php
# In the lambda
handler.js
test.php
bin/php
bin/php is created by my serverless plugin which generates it when running serverless deploy or serverless package. I want this file on the lambda, but not in my project.
I would like the lambda to be generated in a temporary directory (where I could add bin/php without affecting my local files).
We are getting closer to my point: I don’t want it in my project at all
Here is another problem: I need to install Composer dependencies (it’s npm for PHP basically) optimized for production in the lambda. I want them optimized for development on my machine.
So serverless deploy optimizes them for production (thanks to my plugin) but then my dev environment is all messed up.