Search code examples
python-3.xgoogle-app-enginegoogle-cloud-platform

Get Google App Engine LocationId at runtime


The new Cloud Tasks python libraries require location as task creation parameter. I can always look up the location and hardcode it, but everything else, including the project name, is available through environment variables. Is there a way to get the locationId (eg. us-central1) from python3 standard environment?


Solution

  • The REST API (and presumably the python client library) for AppEngine can return the location id if you know the application name:

    https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps/get

    The Application object that is returned has a "locationId" key.

    However, note that the cloud tasks documentation calls out 2 exceptions to verbatim using this identifier: europe-west and us-central need to be passed to tasks as europe-west1 and us-central1 respectively.