Suppose that you are developing a Serverless Framework Plugin, this just gives you a nice way to test it out locally, so you can check your sanity as you go! 🙂

Directory Structure

Suppose that you are developing your plugin in my_shiny_new_serverless_plugin. This is what we will build our directory tree like:

.
├── my_shiny_new_serverless_plugin
│   ├── node_modules
│   │   └── ...
│   ├── src
│   │   ├── my_shiny_new_serverless_plugin.js
│   │   └── ...
│   ├── package-lock.json
│   └── package.json
│
├── test_serverless_plugin_folder
│   ├── index.js
│   └── serverless.yml

Now, if we are in my_shiny_new_serverless_plugin. Do the following:

cd ..
mkdir test_serverless_plugin_folder
cd test_serverless_plugin_folder
serverless create --template aws-nodejs
mkdir custom_serverless_plugins
ln -s ../my_shiny_new_serverless_plugin/ ./custom_serverless_plugins/my_shiny_new_serverless_plugin

So, we have created an aws-nodejs template, which will be enough for testing our new plugin. We have symlinked our new plugin into a plugin folder in the template too, which means that changes as we develop will be seen when we test, with no additional effort.

Now we need to tell the serverless test template that our plugin lives in the folder custom_serverless_plugins, by adding the following to the serverless.yml.

plugins:
  localPath: './custom_serverless_plugins'
  modules:
    - my_shiny_new_serverless_plugin

Now you can sls deploy away, Happy dev testing, now to code & eventually add proper test scripts :)