Determine what project id my App Engine code is running on

I also added an app version, in case you need it too.

import com.google.appengine.api.utils.SystemProperty;


String appId = SystemProperty.applicationId.get();
String appVersion = SystemProperty.applicationVersion.get();

I tried the other approaches in 2019 using Python3. So far as I can tell, those approaches are for Python2 (and one for Java).

I was able to accomplish this in Python3 using:

import os

app_id = os.getenv('GAE_APPLICATION')
print(app_id)
project_id = os.getenv('GOOGLE_CLOUD_PROJECT')
print(project_id)

source: https://cloud.google.com/appengine/docs/standard/python3/runtime


This is the "official" way:

from google.appengine.api import app_identity

GAE_APP_ID = app_identity.get_application_id()

See more here: https://developers.google.com/appengine/docs/python/appidentity/


You can get a lot of info from environment variables:

import os
print os.getenv('APPLICATION_ID')
print os.getenv('CURRENT_VERSION_ID')
print os.environ