You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Environment vars (through environment under both provider and in the actual function declaration in serverless.yml doesn't seem to be supported. Furthermore, there isn't even a warning about it. As someone pretty much forced to deploy something on GCF as opposed to AWS Lamda this is rather confusing and an obvious feature to have. Is there somewhere I can find documentation about this?
As far as I can tell Google's Cloud Functions don't support environment variables. Google's API documentation for Functions doesn't seem to make any reference to them.
I haven't tried it, but you may be able to use the dotenv npm package along with including a .env file in the upload to Google to get environment variables loaded in.
I've also seen where people added build steps to create files to include instead of using environment variables. This is an article that I have seen written on the subject.
I was not able to make it work with dotenv npm package. I've installed serverless-dotenv-plugin which from the documentation looks more optimized for AWS rather than for Google Cloud.
I've got it working by putting environment variables in a separate js file, referencing it in index.js and make sure it's not included as part of commits :)
Totally a workaround which shouldn't be use in any production code. Too bad this feature is not yet available...
It looks like environment variables are a beta feature in Google's API now, so adding this feature shouldn't be too hard. It would be very similar to how I added labels (#95)
Reacted by Takashi Saito, leofidus, Robin Graillon, Cirdes and Ahmed Elshalaby
Nevermind it's the same as aws config. Can this be updated in the google cloud docs? Maybe a general section on general valid config options that works for every provider.
Activity
jbutz commentedon Jan 24, 2018
As far as I can tell Google's Cloud Functions don't support environment variables. Google's API documentation for Functions doesn't seem to make any reference to them.
I haven't tried it, but you may be able to use the dotenv npm package along with including a
.envfile in the upload to Google to get environment variables loaded in.I've also seen where people added build steps to create files to include instead of using environment variables. This is an article that I have seen written on the subject.
aaronkchsu commentedon Apr 25, 2018
I mean how far away is this feature?? :(
adimoraret commentedon Aug 10, 2018
I was not able to make it work with dotenv npm package. I've installed serverless-dotenv-plugin which from the documentation looks more optimized for AWS rather than for Google Cloud.
I've got it working by putting environment variables in a separate js file, referencing it in index.js and make sure it's not included as part of commits :)
Totally a workaround which shouldn't be use in any production code. Too bad this feature is not yet available...
hamikm commentedon Aug 13, 2018
+1 would love to see this feature
jbutz commentedon Aug 16, 2018
It looks like environment variables are a beta feature in Google's API now, so adding this feature shouldn't be too hard. It would be very similar to how I added labels (#95)
nethunter commentedon Aug 31, 2018
I created a pull request that adds environment variables 2 weeks ago: #117
mrdulin commentedon Sep 21, 2018
Need this feature
nethunter commentedon Sep 21, 2018
You can use my pull request (#117) for now, I've been using it for 2 months with no problems.
mrdulin commentedon Sep 21, 2018
@nethunter How can I use it?
nethunter commentedon Sep 21, 2018
@mrdulin replace your serverless-cloud-functions line in package.json with this:
and then in serverless.yml, under your provider add "environment" and add all the environment variables you want
mrdulin commentedon Sep 25, 2018
@nethunter thanks. It works. I made a sample for passing environment variables:
.env=>serverless.yml=>cloud functionshttps://github.com/mrdulin/nodejs-serverless-framework/tree/master
pickypg commentedon Oct 23, 2018
Now that #117 is merged, this can be closed.
pmuens commentedon Nov 12, 2018
Thanks for opening @blackxored and thanks for updating @pickypg 👍
The latest version of this plugin supports env vars. Closing...
ncjones commentedon Mar 12, 2019
Where's the docs?
pizzarob commentedon Aug 2, 2019
@pmuens How can environment variables added via serverless.yml be used within cloud functions ?
pizzarob commentedon Aug 2, 2019
Nevermind it's the same as aws config. Can this be updated in the google cloud docs? Maybe a general section on general valid config options that works for every provider.