Is there a way calling FindDefaultCredentials successfully using 2nd gen local app engine (dev_appserver.py)?

Viewed 370
2 Answers

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 ..

  • Passing command line parameter --support_datastore_emulator=true to dev_appserver.py
  • Passing command line parameter --datastore_emulator_port=9090 to dev_appserver.py
  • Setting environment variable DATASTORE_EMULATOR_HOST to localhost:9090 in app.yaml
  • Setting environment variable 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).

Related