I'm attempting to access Firestore from within an AWS Elastic Beanstalk deployment. The EB application is written using Flask in Python, and everything works correctly locally. But, when I try to deploy to EB, only the first database request succeeds-- the second one freezes my application during the call to .get()
.
I'm not sure if this is a permissions thing on EB, a Firestore issue, or what! Since no exception is thrown, I can't even deny the request and move on.
I do get the following in the logs:
[Tue Jun 26 11:29:16.964989 2018] [core:error] [pid 3914] [client 172.31.17.165:22711] Script timed out before returning headers: application.py
... but that's because the script is timing out due to the call to .get()
never returning.
Here's my full code for this test app:
import os
from flask import Flask, url_for, redirect, render_template
import mimetypes
import time
import google
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
print("=====================================================")
print("initializing app")
cred = credentials.Certificate("/my/actual/path/to/credentials/is/here.json")
firebase_admin.initialize_app(cred)
print("done.")
print("initializing firestore")
db = firestore.client()
print("done.")
print("initializing flask")
application = Flask(__name__)
print("done.")
@application.route('/doc/<docId>')
def doc(docId):
docId = docId.lower()
documents_ref = db.collection(u'documents')
doc_ref = documents_ref.document(docId)
print("getting doc")
doc = None
try:
doc = doc_ref.get()
except google.cloud.exceptions.NotFound:
print("not found.")
return render_template('doc.html', message="This document no longer exists .")
print("done.")
# Here is where I'd normally use the DB snapshot data, but omitted for the question
creatorStr = "Someone"
timeStr = "a time"
docMessage = creatorStr + " sent you a document dated " + timeStr + "."
return render_template('doc.html', docMessage=docMessage)
if __name__ == "__main__":
# application.debug = True
application.run()
Any help would be greatly appreciated!