I'm developing an app engine application using the "go111" runtime. According to Migrating your App Engine app from Go 1.9 to Go 1.11 accessing the datastore should be done using package datastore. However, calling google.FindDefaultCredentials fails with "could not find default credentials". Any ideas how to access the datastore using default credentials?
Set the GOOGLE_APPLICATION_CREDENTIALS
environment variable before starting your application.
With the second generation runtime, if you aren't using any google.golang.org/appengine
APIs, you do not need to use dev_appserver.py
-- you can build and start your application normally (go build
and/or go run
).
Also, it's very uncommon to explicitly pass the credentials. cloud.google.com/go
APIs should all automatically find your credentials for you. When you're running locally, setting the GOOGLE_APPLICATION_CREDENTIALS
and GOOGLE_CLOUD_PROJECT
environment variables should be enough to get running. See https://cloud.google.com/docs/authentication/production#obtaining_credentials_on_app_engine_standard_environment (note the comment about this being uncommon).
I just got it working using local app engine SDK by ..
--support_datastore_emulator=true
to dev_appserver.py
--datastore_emulator_port=9090
to dev_appserver.py
DATASTORE_EMULATOR_HOST
to localhost:9090
in app.yaml
DATASTORE_PROJECT_ID
to my project id
in app.yaml
In my Go 1.11 code, I simply create a new cloud.google.com/go/datastore
client using datastore.NewClient(ctx, "")
, which picks up the environment variables and connects to the local datastore emulator (running as part of dev_appserver.py
).