I'm trying to deploy my Flask application to AWS and am getting a 403 Forbidden error. After much testing with AWS, I've seemed to figure out that it's an error on there end. My Flask App currently is written using an application factory, and looks something like this (simplified):
from flask import Flask
def create_app(test_config=None):
application = Flask(__name__)
app = application
@app.route('/')
def index():
return "The index page"
...
return app
However, after I set up an environment on Elastic beanstalk and deploy my Flask app there, I visit the index page, I get a 403 Forbidden error. I check my logs for EB, and see an error saying
"Target WSGI script '/opt/python/current/app/server/application.py' does not contain WSGI application 'application'."
At first I was confused. I had previously had other errors with EB and had looked online. I don't really understand what the WSGI standard is, but I saw people saying that EB will only work if the Flask "app" object is named "application", which I purposefully changed. Then I looked at the AWS documentation and realized their examples didn't use an application factory, so on a hunch I tested not using the application factory:
from flask import Flask
application = Flask(__name__)
app = application
...
@app.route('/')
def index():
return "The index page"
if __name__ == "__main__":
application.run()
This worked. I can only conclude that because the "application" object is defined in the application factory, or the fact that it's returning the application instead of using application.run(), it isn't registering with EB. Again, I don't really understand WSGI and what it has to do with the error. How can I get around this and deploy with the application factory, since I don't want to get around rewriting most of my project?