Sometimes users need custom functionality that the core serverless framework doesn't do out of the box.
To achieve this, users can extend the base cli functionality by tapping into lifecycle hooks or creating new hooks.
Examples:
- Transpile es6 or typescript code on
before:package
hook - Scanning dependancies for security vulnerabilities on
before:deploy
hook - Tapping into the
after:deploy
hook to run additional CI/CD workflows - Wiring up custom domains on
after:deploy
hook - etc
There are a ton of serverless plugins out there.
-
Discovering Plugins
Via the CLI:
sls plugin list
Online:
Head to the Serverless Plugins repository for a list of available plugins
-
Installing Plugins
sls plugin install -n serverless-manifest-plugin
This command will install the plugin into your node_modules folder and save it to the package.json devDependencies.
The command also automatically added this plugin to the
plugins
array inserverless.yml
plugins: - serverless-manifest-plugin
-
Configuring Plugins
Plugins handle a wide variety of use cases and thus have their own configuration requirements. Make sure to read the README.md of the plugin you are using to add any additional configuration it may require.
Typically plugins will use settings defined in a
custom
key inserverless.yml
# example custom: output: file: .serverless/manifest.json
This will output cloudformation values into a
manifest.json
file for us for easily plugging into a frontend application -
Removing Plugins
sls plugin uninstall -n serverless-manifest-plugin
Typically this works but some plugins aren't validating inputs. If you run into any errors, manually remove the plugin from the
plugins
array in theserverless.yml
file
Building a plugin is very straight forward. Check out these resources for more information:
- How To Write Your First Plugin For The Serverless Framework - Part 1
- How To Write Your First Plugin For The Serverless Framework - Part 2
- Super Simple Plugin Boilerplate
If you need help or get stuck refer to the completed code of this lesson