Environment variables with Google Cloud Functions

google

#1

Hi guys,

Thanks for a great product!

Using the current master with GCF.

I was wondering if there was a way to specify environment variables to functions like in AWS.

Couldn’t find anything in the doc, and adding an “environment” section to the provider section doesn’t seem to work.

provider:
  name: google
  runtime: nodejs
  project: my-proj
  # the path to the credentials file needs to be absolute
  credentials: ~/.gcloud/keyfile.json
  environment:
    STAGE: ${opt:stage}

When I try to read the environment variable STAGE in the functions, it is undefined
Works with AWS though.

Thanks,
Roy.


#2

Currently Google Cloud Functions does not support environment variables like AWS Lambda does. Its a feature they still need to add. Perhaps consider joining their Beta Google Cloud Functions mailing group to find out more.


#3

I actually asked a similar question on SO a few days ago, since I wanted to handle the credentials through env variables (I wasn’t using Serverless at all then)

And no, no solution so far. Using Serverless is actually a solution for my use case since I can store the credential on the dev computer and run serverless which zip the credentials somehow, in a secure way I assume. But I don’t need to put the credential file in my git repository like I did before, which is much better anyway.


#4

Recently Cloud Functions supports environment variables: https://cloud.google.com/functions/docs/env-var


#5

Is now there a way to provide environment variables for GCF function in serverless.yml file?