GithubHelp home page GithubHelp logo

serverless-nconfig's Introduction

serverless npm version npm downloads Donate

Installation

npm i -E serverless-nconfig

Before configure your environments files.

.
├── serverless.yml
├── config
│   ├── custom-environment-variables.yaml
│   ├── default.js
│   ├── develop.js
│   ├── testing.js
│   ├── production.js

Feature

- Support all "node-config" features.
- Fetch Config from Aws CloudFormation Stack Outputs.
- Fetch Secret from VAULT.
- Fetch Config from AWS - SSM.

Usage

plugins:
  - serverless-nconfig

custom:
  dbPort: ${config:db.mysql.port:3306}
  prop2: ${config:path.to.required.value}
  prop2: ${config:some.path:DEFAULT_VALUE_HERE}

Test - Render Serverless Config

$ serverless print --stage develop
$ serverless print --stage testing
$ serverless print --stage production

Fetch Secret From Aws - SSM

// file: config/default.js
const { GetFromSSM } = require('serverless-nconfig/src/resolvers');

const stage = process.env.SLS_STAGE;
const region = process.env.AWS_REGION;

module.exports = {
  db: {
    mysql: {
      port: 3306,
      user: admin,
      passwd: GetFromSSM(`/${stage}/MY_SQL_PASSWORD`, true)
    }
  },
};

Fetch Secret From Vault. Option 1

// file: config/default.js
const GetFromVault = require('serverless-nconfig/src/resolvers/vault')({
  host: 'vault.corp.com',
  token: '____TOKEN___HERE___'
});


module.exports = {
  db: {
    mysql: {
      port: 3306,
      user: admin,
      passwd: GetFromVault('/team/service/name/mysql-password'),
    }
  },
};

Fetch Secret From Vault. Option 2

// file: config/default.js
const GetFromVault = require('serverless-nconfig/src/resolvers/vault')({
  host: 'vault.corp.com',
  roleId: '____ROLE_ID___HERE___',
  secretId: '____SECRET_ID___HERE___'
});


module.exports = {
  db: {
    mysql: {
      port: 3306,
      user: admin,
      passwd: GetFromVault('/team/service/name/mysql', 'resp.path.to.mysql.pass')
    }
  },
};

Fetch Config From: Aws - Cloud Formation Stack Outputs.

// file: config/default.js

const { GetFromStackOutput } = require('serverless-nconfig/src/resolvers');

const stackName = 'my-app-service'
const stage = process.env.SLS_STAGE;

module.exports = {
  app: {
    redisUrl: GetFromStackOutput(`app-infra-${stage}`, 'redisUrl'),
    dynamoUrl: GetFromStackOutput(`app-infra-${stage}`, 'dynamoUrl'),
    cloudFrontUrl: GetFromStackOutput(`${stackName}-${stage}`, 'CloudFrontUrl')
  },
};

Configuration References

https://github.com/lorenwest/node-config

Donation

Donate helps me to continue adding new features or bugs fix..

paypal

serverless-nconfig's People

Contributors

w4rlock avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.