Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set environment variables on google appengine?

I'm trying to set and use an environment variable on google app engine. My app.yaml file looks as below. However when I use os.Getenv("mytoken") I get an empty string instead the actual value I set. Is it a GAE bug?

api_version: go1
handlers:
- url: /.*
  script: _go_app
env_variables:
  mytoken: '88786d9b9a0359824'
like image 531
The user with no hat Avatar asked Mar 21 '15 17:03

The user with no hat


People also ask

What is App Engine standard environment?

The App Engine standard environment is based on container instances running on Google's infrastructure. Containers are preconfigured with one of several available runtimes. The standard environment makes it easy to build and deploy an application that runs reliably even under heavy load and with large amounts of data.

How do I set environment variables in cloud run?

To set, update, or remove environment variables of an existing service, use the gcloud run services update command. You can use any of the following flags, as needed: --set-env-vars. --update-env-vars.


1 Answers

The feature is now documented here. However, as I have tested just now, it doesn't work on AppEngine. It does work on local server, so don't be fooled..

Edit: It works on Google AppEngine. My previous failure is due to a mistake. Consider this:

import "os"

var consumer = OAuth1Consumer{
    secret: os.Getenv("secret")
}

It does not work if you declare as global variable.

like image 200
Chunliang Lyu Avatar answered Sep 19 '22 14:09

Chunliang Lyu