python - How to use Google Cloud Datastore from existing Compute Engine with different project id? -
google cloud datastore great way share information between app engine , compute engine. this instruction shows how use google cloud datastore compute engine, seems both app engine , compute engine have in same project id.
my datastore inside app engine , compute engine have different project id.
here did. in googledatastore/helper.py around line 65, added 1 line
try: raise client.accesstokenrefresherror # <== added credentials = gce.appassertioncredentials(connection.scope) http = httplib2.http() credentials.authorize(http) credentials.refresh(http) logging.info('connect using compute credentials') return credentials except (client.accesstokenrefresherror, httplib2.httplib2error): if (os.getenv('datastore_service_account') , os.getenv('datastore_private_key_file')): open(os.getenv('datastore_private_key_file'), 'rb') f: key = f.read() credentials = client.signedjwtassertioncredentials( os.getenv('datastore_service_account'), key, connection.scope) logging.info('connect using datastoresignedjwtcredentials') return credentials
then ignored compute engine credential. after follow instruction 'not compute engine'. hm.. doesn't best way.
is proper way use datastore compute engine under project id?
i recommend consolidate compute engine , app engine under same project, if reason not possible try following:
- visit app engine admin console (for app engine app)
- select application id google cloud datastore api should enabled.
- click application settings link within left hand navigation.
- scroll cloud integration section.
- if no project showing up, click add project. project creation take few minutes, wait until see google apis console project number in basics section of application settings page.
- click on google apis console project number link.
- select apis list of services.
- scroll google cloud datastore api.
- switch google cloud datastore api off on.
- visit google cloud console (for compute project)
- select existing project id google cloud datastore api should enabled.
- select apis list of services.
- scroll google cloud datastore api.
- switch google cloud datastore api off on.
- go permissions
- copy compute service account email address (should like: projectid@project.gserviceaccount.com)
- visit google cloud console (for app engine app)
- go permissions
- add compute service account email address
and should work unmodified python client.
Comments
Post a Comment