Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jgardezi commented on 14 Feb 2017 •
- Below are the steps I have done to solve this.
- 1- Create env.yml file. The structure of this file looks like this.
- `
- // env.yml
- local:
- host: localhost
- port: 5432
- name: mydb
- user: root
- password: secret
- dev:
- host: db.myserver.com
- port: 5432
- name: mydb
- user: root
- password: secret
- `
- In the env.yml file there are two environment local and dev. local is testing on local development environment variables. dev is for the cloud hosting environment.
- 2- To reference env.yml in serverless.yml so that we deploy microservice based on the env variables i.e. sls deploy --s local or sls deploy --s dev
- // serverless.yml provider: stage: local environment: ${file(./env.yml):${opt:stage, self:provider.stage}}
- That's all we need, to configure the multi-env. I have customised it further so that we don't need to run sls deploy --s local. The environment picks automatically local and all we need is sls deploy command.
- 3- Lastly, if you need to refer the variables in .js files all you need to do is call them like
- // PostgreSQL database connection parameters: var config = { host: process.env.host, port: process.env.port, database: process.env.name, user: process.env.user, password: process.env.password, };
- I hope above solves lot of issues.
- Kind regards,
- Javed Gardezi
Add Comment
Please, Sign In to add comment