npm i -E serverless-nconfig
.
├── serverless.yml
├── config
│ ├── custom-environment-variables.yaml
│ ├── default.js
│ ├── develop.js
│ ├── testing.js
│ ├── production.js
- Support all "node-config" features.
- Fetch Config from Aws CloudFormation Stack Outputs.
- Fetch Secret from VAULT.
- Fetch Config from AWS - SSM.
plugins:
- serverless-nconfig
custom:
dbPort: ${config:db.mysql.port:3306}
prop2: ${config:path.to.required.value}
prop2: ${config:some.path:DEFAULT_VALUE_HERE}
$ serverless print --stage develop
$ serverless print --stage testing
$ serverless print --stage production
// 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)
}
},
};
// 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'),
}
},
};
// 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')
}
},
};
// 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')
},
};
https://github.com/lorenwest/node-config
Donate helps me to continue adding new features or bugs fix..