I am trying to set up a simple cloud function and connect to my Google Cloud Platform datastore. It all works when I run it in Google colab but when I try running it as a cloud function it fails. When I strip it down to see where it fails it seems to fail already when I try to use:
from google.cloud import datastore
The entire code looks like this:
def gdl_find_noTranslate(request):
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="cred.json"
request_json = json.loads(request)
if request_json and 'bookId' in request_json:
book_id = request_json['bookId']
# Instantiates a client - have removed the real names
client = datastore.Client(project='my-project', namespace='my-namespace')
if request_json and 'kind' in request_json:
entity_kind = request_json['kind']
# Find book kind for the new entity
key = client.key(entity_kind, book_id)
query = client.query(kind=entity_kind)
# if bookid is in parameters - add filter
if request_json and 'bookId' in request_json:
query.add_filter('bookID', '=', book_id)
results = list(query.fetch())
return results
requirements.txt
file? - Dustin Ingramrequirements.txt
- Vikram Shinde