I am trying to deploy a Flask app on Heroku. Whenever I make a request to the server, my Heroku log gives me an H12 timeout error without any other information:
2018-06-25T21:25:58.755278+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=live-event-market-api.herokuapp.com request_id=a1638941-9d56-4364-b9e6-ba46b6fa875f fwd="73.186.40.243" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
After a great deal of searching, I realized that the problem had to do with connecting to my database: when I comment out the code which connects to the database, requests to the app on Heroku work fine.
#create all db tables
@app.before_first_request
def create_tables():
from database import init_db
init_db()
#^^^get rid of all this, and the app works fine on Heroku
After looking at this, I decided that I needed to SSL certify heroku. I have gone through the steps, and it seems like I should be connecting successfully. However, it's very hard to accurately debug this without any kind of error messages (like this one reported by another SO poster).
Does anybody have any idea how I can get a better stack trace from Heroku here? I can't know what the error is unless my code tells me--all I know is that, for some reason, my Heroku dyno can't connect to my Amazon RDS MySQL database within 30 seconds.
Note also that my app works perfectly on my local machine. It is only when I push it to Heroku that I start having troubles.
Edit: Note too how I'm trying to connect to the DB:
engine = create_engine(os.environ['DB_URI'],connect_args={'ssl':{'ca':'amazon-rds-ca-cert.pem','cert':'amazon-rds-ca-cert.pem'}})
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()
def init_db():
from models import UserModel, RevokedTokenModel, PromoterModel, EventInfo, Event
Base.metadata.create_all(bind=engine)
Where DB_URI is a config variable with a valid AWS instance's url.