Serverless recommends to install itself globally. This is notably required to make commands such as “serverless” or the shortcut “sls” available in the command line.
However, projects created to Serverless 0.5 cannot be deployed using Serverless 1.x. So, with the official instructions, if you have one project in Serverless 0.5 and the other in Serverless 1.x, you’re basically screwed.
Gladly, it’s actually fairly easy to use a non-global installation of Serverless.
Basically, you just need to install Serverless locally (and while you’re at it, mark it as a development dependency):
npm install firstname.lastname@example.org --save-dev
You might want to have a look in your package.json file and lock down the version completely, if that you want (I believe that by default, minor revisions are allow, ie 0.5.5 may get upgraded to 0.5.6).
Then, you need to recreate the “serverless” or “sls” command (or whatever alias you want). For this, simply create a bash file (Windows
.sh), in your project’s root folder, with the following content:
– on Windows:
node node_modules\serverless\bin\serverless %*
– on Linux or Mac:
node node_modules\serverless\bin\serverless $*
Finally, to run
serverless dash deploy, for instance, if you named your bash file
slslocal.bat, just run instead:
slslocal dash deploy