https://github.com/hieuunguyeen/serverless-header-function
[sls@0.5x] Run a js file locally for every registered Serverless actions
https://github.com/hieuunguyeen/serverless-header-function
lambda serverless
Last synced: about 1 year ago
JSON representation
[sls@0.5x] Run a js file locally for every registered Serverless actions
- Host: GitHub
- URL: https://github.com/hieuunguyeen/serverless-header-function
- Owner: hieuunguyeen
- License: mit
- Created: 2016-10-27T13:34:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-26T10:12:23.000Z (about 9 years ago)
- Last Synced: 2025-03-08T18:35:36.969Z (about 1 year ago)
- Topics: lambda, serverless
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Serverless header function
Run a js file locally for every registered Serverless actions
[](http://www.serverless.com)
> 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
3. 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]
}
]
}
```
2. 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
```
3. Params will be digested in `require(path).apply(params)` manner. Therefore in the header function file, retrieve params by calling lexical `arguments`
4. The second last of the params will be the **Serverless** object which contains Serverless classes and actions
5. The last of the params will be the **context** object which contains information about the serverless action
6. Exports the file as a single function without input parameter
`module.exports = function () { console.log(a,b) }`
7. Profit!