Skip to content

[sls@0.5x] Run a js file locally for every registered Serverless actions

License

Notifications You must be signed in to change notification settings

hieuunguyeen/serverless-header-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless header function

Run a js file locally for every registered Serverless actions

serverless

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:

  1. Running a function by a hook
  2. Serially execute multiple functions. TODO: Support Async

Usage:

  1. List all js path file relative to project root in s-project.json under custom.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]
      }
    ]
}
  1. Hooks are in the format of target-hook-action. target and hook 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
  1. Params will be digested in require(path).apply(params) manner. Therefore in the header function file, retrieve params by calling lexical arguments
  2. The second last of the params will be the Serverless object which contains Serverless classes and actions
  3. The last of the params will be the context object which contains information about the serverless action
  4. Exports the file as a single function without input parameter module.exports = function () { console.log(a,b) }
  5. Profit!

About

[sls@0.5x] Run a js file locally for every registered Serverless actions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published