
Serverless Scripts Env
Introduction
This plugin aims to answer a specific need and to simplify the assignment of environment variables with serverless either front-end or back-end.
Installation
Install the plugin using either Yarn or NPM. (we use Yarn)
NPM:
npm install @unly/serverless-scripts-env
YARN:
yarn add @unly/serverless-scripts-env
Usage
Step 1: Load the Plugin
The plugin determines your environment during deployment and adds all environment variables to your Lambda function.
All you need to do is to load the plugin:
Must be declared before serverless-webpack, despite what their officially doc says
plugins:
- '@unly/serverless-scripts-env'
- serverless-webpack
Step 2: Configure your serverless.yml
Set the slsScripts object configuration as follows (list of all available options below):
custom:
slsScripts:
offline:
logName: client
script:
cmd: next
args:
- -p 3001
path:
env:
exclude:
- SECRET_KEY
provider:
name: aws
runtime: nodejs6.10
environment:
GROUP_NAME: staging
SECRET_KEY: f08ed2dc-edeb-45f4-9cac-56012820a384
Configuration of slsScripts object:
| offline | Object | false | script to run before cli serverless-offline start |
| build | Object | false | script to run before cli serverless deploy or serverless package |
offline & build object:
| logName | String | false | Serverless-scripts-env | name of the command that appears in the terminal being executed |
| script | Object | true | | |
| path | String | false | current working directory | Absolute Path to run the script |
| env | Object | false | | |
script object :
| cmd | String | true | | command to execute |
| args | Array of String | false | [ ] | command arguments to execute |
env object :
| exclude | Array of String | false | | environment variables to blacklist |
Try it out yourself
To test this plugin, you can clone this repository.
Go to examples/, and follow the README.
API
API
Contributing
We gladly accept PRs, but please open an issue first so we can discuss it beforehand.
Getting started
yarn start # Shortcut - Runs linter + tests in concurrent mode (watch mode)
OR run each process separately for finer control
yarn lint
yarn test
Test
yarn test # Run all tests, interactive and watch mode
yarn test:once
yarn test:coverage
Releasing and publishing
yarn releaseAndPublish # Shortcut - Will prompt for bump version, commit, create git tag, push commit/tag and publish to NPM
yarn release # Will prompt for bump version, commit, create git tag, push commit/tag
npm publish # Will publish to NPM
Node support
This plugin officially supports Node.js 6.10 and 8.10.
License
MIT