I've specified my environment variables in app.yaml and it's being fetched when I'm running it on my local machine but once I have it deployed - it's not fetching it.
Here's how I've set it up:
application: some-application
version: 1
runtime: go
api_version: go1
threadsafe: true
handlers:
- url: /.*
script: main.go
secure: always
env_variables:
ENVIRONMENT_VAR1: 'some key'
ENVIRONMENT_VAR2: 'some key'
ENVIRONMENT_VAR3: 'some key'
And I'm using os.Getenv("ENVIRONMENT_VAR1")
to retrieve the key and it works when I run it on my local but fails to work when deployed on google app engine.
It is undocumented in the official doc: Defining environment variables, but environment variables defined in
app.yaml
in production are not set beforeinit()
functions are called. They are only set before serving the first request.This issue was reported here. Quoting an AppEngine engineer's answer:
Example of achieving this with
Once.Do()
:The answer icza provided worked for me. In addition, I put the once.Do() call in a handler for the /_ah/start method so that it would be called immediately when GAE started up my application.