'Django app running fine on localhost, but not working on elastic beanstalk 500 internal errors
I have a django app, and it works fine on localhost (no problems). It loads a json file into a data structure (Trie), and is being used in a single route. It takes about 2-3 seconds for the file to be read, and build the Trie (there are thousands of words in my list). All of this is fine localhost as it only takes 2-3 seconds a single time (when you start the server). Then when you call a route on the front end with a POST to the route it performs the search on the Trie and returns the results (OK). Everything works fine localhost. However whenever I try this same exact approach on AWS Elastic Beanstalk, it returns 500 Internal Server Error on every route (routes that don't use this Trie are also throwing this exact same error code). So I am going to show some relevant code as to how I load the file, and how it is used in the app.
module_dir = os.path.dirname(__file__)
file_path = os.path.join(module_dir, 'trie.json')
myTrie = Trie()
myTrie.load(file_path)#Loads the trie from a json file that is just a list(array)
...
...
#in search view post route
return Response(myTrie.search(word)) #note word is part of the request body.
This all works perfectly fine localhost, and it finds and loads the file into the Trie perfectly, however this exact same code causes all routes (not just the search routes, or user routes etc) to return a 500 Internal Error (not 502 bad gateway), the entire app is unusable when this gets deployed to the app... Oddly enough if I don't call MyTrie.load(file_path) the app remains up and all routes work (however the trie has no data to search making the route useless).
Here is part of the structure my app uses:
MyAPP:
MyAppEnv
MyApptrie.py
manage.py
users
requirements.txt
Procfile
...
searchviews.py
trie.json
Another thing I would like to mention is that for it to work localhost I need to import Trie in manage.py like from MyApp.trie import Trie. However it 100% works localhost no problems.
I'm thinking this is a problem with reading the file when it is uploaded to elastic beanstalk, but I'm not sure. If it were a problem with loading the file, then why does it deploy as OK, but every route gives a 500 internal server error (except the "/" route).
How would I go about debugging this problem to see what the issue is, and what exactly is the issue? Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
