Guest User

Untitled

a guest
Feb 26th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. jgardezi commented on 14 Feb 2017 •
  2. Below are the steps I have done to solve this.
  3.  
  4. 1- Create env.yml file. The structure of this file looks like this.
  5. `
  6. // env.yml
  7. local:
  8. host: localhost
  9. port: 5432
  10. name: mydb
  11. user: root
  12. password: secret
  13.  
  14. dev:
  15. host: db.myserver.com
  16. port: 5432
  17. name: mydb
  18. user: root
  19. password: secret
  20. `
  21.  
  22. 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.
  23.  
  24. 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
  25.  
  26. // serverless.yml provider: stage: local environment: ${file(./env.yml):${opt:stage, self:provider.stage}}
  27.  
  28. 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.
  29.  
  30. 3- Lastly, if you need to refer the variables in .js files all you need to do is call them like
  31. // 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, };
  32.  
  33. I hope above solves lot of issues.
  34.  
  35. Kind regards,
  36. Javed Gardezi
Add Comment
Please, Sign In to add comment