serverless-header-function
v1.6.0
Published
Run a js file locally for every registered Serverless actions
Downloads
12
Readme
Serverless header function
Run a js file locally for every registered Serverless actions
Not compatible with Serverless 1.0.0 and above
Installation
Make sure you have Node.js v4.0+ and Serverless Framework installed Install plugin in the root level of your Serverless project
npm install --save-dev serverless-header-function
Append the plugin's name to serverless plugins list in s-project.json
plugins: [
"serverless-header-function"
]
Current supports:
- Running a function by a hook
- Serially execute multiple functions. TODO: Support Async
Usage:
- List all js path file relative to project root in
s-project.json
undercustom.headerfunctions
, the disired hook and params.
custom: {
headerfunctions: [
{
path: 'lib/func-a.js',
hook: 'function-pre-run',
params: []
},
{
path: 'src/a/b/c/function-bcde.js',
hook: 'function-post-deploy',
params: ['a', 1, null, true]
}
]
}
- Hooks are in the format of
target-hook-action
.target
andhook
input are mandatory. Currently supported input are:
target: enum['function','endpoint', 'event']
hook: enum['pre', 'post']
action: enum['run', 'deploy'] // only function support `run` action
params: array
- Params will be digested in
require(path).apply(params)
manner. Therefore in the header function file, retrieve params by calling lexicalarguments
- The second last of the params will be the Serverless object which contains Serverless classes and actions
- The last of the params will be the context object which contains information about the serverless action
- Exports the file as a single function without input parameter
module.exports = function () { console.log(a,b) }
- Profit!