serverless-enhanced-config v0.0.2-0
serverless-enhanced-config
A serverless plugin to enhance configuration with template features and easier variable handling.
serverless-enhanced-config uses mustache.js to improve Serverless Framework configuration functionality, flexibility and reusability.
An enhanced configuration is rendered in runtime - based on provided template and variables - and then used by serverless, replacing the regular one.
Installation
You can install serverless-enhanced-config via npm:
npm install serverless-enhanced-configor yarn:
yarn add serverless-enhanced-configUsage
Using the plugin is quite simple. You'll need:
1. A valid serverless configuration to load serverless-enhanced-config, its settings and variables. For instance, the following serverless.yml:
service: helloworld #=> mandatory: serverless needs it
plugins:
- serverless-enhanced-config
provider: #===========> mandatory: serverless needs it
name: aws
custom:
enhancedConfig: #===> plugin setup with template and variables
template: template.yml
variables:
function:
name: myfunc
handler: handlers/myfunc.main
path: mypath/myfunc
method: get- A template with proper variables placeholders. For example, the
template.ymlbelow:
service: helloworld
package:
individually: true
plugins:
- serverless-dotenv-plugin
provider:
name: aws
runtime: nodejs12.x
stage: ${opt:stage, env:stage, 'dev'}
region: ${opt:region, env:region, 'us-east-1'}
functions:
{{ function.name }}:
handler: {{ function.handler }}
events:
- http:
path: {{ function.path }}
method: {{ function.method }}
authorizer: aws_iamAll set! You can see the enhanced configuration generated by using the serverless built-in print command:
sls printFeatures
Most of the mustache.js features are supported, such as:
- Template and variables decoupled
- Partials (or includes)
- Sections
- Custom delimiters
Serverless native variables ${self.*}, ${env.*} and ${opt.*} are supported within variables and template/partials. Same is true for file includes ${file(*)}.
Examples
Author
Ricardo Aielo @aielo
License
serverless-enhanced-config is licensed under the ISC License.
6 years ago