Reputation: 63
I want to put a very simple website on Amazon EB using Flask framework. The website has a welcome form, it takes two values from the user, reads an SQLite database and shows results on the screen. The website works perfectly on my local machine. The problem is on the Elastic Beanstalk.
I create a zip file with the application.py, the SQLite database, the static folder (for bootstrap) and templates folder (for the two templates) and I upload it on the Elastic Beanstalk. My system is windows, running python 3.6. After the upload, EB gives me green status. I click the link on the EB and takes me to the form. All working good so far. Then when I click on the form the button submit to take me to the results page but instead I receive:
Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
I worked the code to identify the step that Amazon EB fails to understand and it seems that the program fails at the line cur.execute('''SELECT a, b, c, d, e, f... which means that the Amazon EB does not see/understand my SQLITE database.
Can someone help?
This is my code for the flask program application.py:
import os
import sqlite3
from flask import Flask, request, render_template
application = Flask(__name__)
@application.route('/', methods=['POST', 'GET'])
def index():
if request.method == 'GET':
return render_template('welcome.html')
elif request.method == 'POST':
conn = sqlite3.connect('Sky.db')
cur = conn.cursor()
weekendid= request.form['weekend']
myData=[]
cur.execute('''SELECT a, b, c, d, e, f, g
FROM Table1 WHERE a = ? ORDER BY g DESC LIMIT 5''', (weekendid,))
row = cur.fetchall()
for i in row:
average_1 = (i[1]+i[3])/2
average_2 = (i[2]+i[4])/2
variable1 = i[5]
variable2 = i[6]
cur.execute('''SELECT * FROM Table2 WHERE a = ?''', (i[0],))
coords=cur.fetchone()
zz = [average_1, average_2,variable1,variable2]
myData.append(zz)
return render_template('where.html', myData=myData)
if __name__ == '__main__':
application.debug = True
host = os.environ.get('IP', '127.0.0.1')
port = int(os.environ.get('PORT', 80))
application.run(host=host, port=port)
Upvotes: 3
Views: 2034
Reputation: 3322
First. Be careful when using SQLite on Elastic Beanstalk, as if you change configuration it is likely to kill your instance and redeploy. In your case, it doesn't look like you are actually writing to the database, so that isn't a problem.
First step of finding the error might be going to the Elastic Beanstalk console and clicking Request logs
. It's under the logs pane.
There you should be able to get the logs from your instance and find the actual error under /var/log/httpd/error_log
.
You might also want to ssh to your instance and verify the paths are as you expect. You can of course also find the logs that way. If you are using the eb console tool, you can simply do eb ssh
Upvotes: 2