46

I'm trying to upload my Flask application to AWS however I receive an error on doing so:

Your WSGIPath refers to a file that does not exist.

After doing some digging online I found that in the .ebextensions folder, I should specify the path. There was not a .ebextensions folder so I created one and added the following code to a file named settings.config:

option_settings:
  "aws:elasticbeanstalk:container:python":
    WSGIPath: project/application.py

the WSGIPath is the correct path to the application.py file so I'm not sure what raises this error. Am I changing the WSGIPath right, is there a better way or is there an issue with something else which causes this to happen? Thanks.

Pav Sidhu
  • 5,399
  • 12
  • 46
  • 95

5 Answers5

45

There's a lot of configuration issues that can arise with Flask deployed on AWS. I was running into a similar issue as you, so I can at least show you what I did to resolve the WSGI error.

First, apparently you can do this without the .ebextensions folder (see this post here. and look at davetw12's answer. However, be aware that while this works, I'm not entirely sure that davetw12's conclusion about .ebextensions is correct, based on some of the comments below). Instead, (in the Terminal), I navigated to my project at the same level as my .elasticbeanstalk directory and used the command eb config. This will open up a list of options you can set to configure your beanstalk application. Go down through the options until you find the WSGI path. I notice you have yours set to project/application.py, however, this should not include the folder reference, just application.py. Here is how it looks on my Mac in the terminal (WSGI path is near the bottom).

enter image description here

Note that once you get that set, EB will probably redeploy. That's fine. Let it.

Once you get that set, go into your application.py file and make sure you call your app application. For example, mine looks like this:

from flask import Flask
from flask import render_template
application = Flask(__name__)

@application.route('/')
@application.route('/index')
def index():
    return render_template('index.html',
                           title='Home')

This took away the WSGI path error - although I still had to fix some other issues following this :-) But that is a different set of questions.

Community
  • 1
  • 1
joshmcode
  • 2,904
  • 1
  • 29
  • 41
  • I have a similar problem, and using `eb config` I discovered that WSGIPath is not in my config data - in fact I get nothing for aws:elasticbeanstalk:container:python. I set it in a .config file, but it appears to be getting overwritten by the saved configuration in the Dashboard - that displays `WSGIPath: application.py` on the front page, but doesn't allow me to edit it anywhere. Looks like I will just have to create an application.py! – Kylotan Jul 22 '15 at 18:03
  • 1
    We had a problem with psycopg2 not installed. adding those lines to our .ebextensions/01-app.config file fixed it: packages: yum: postgresql93-devel: [] – Gal Bracha Aug 08 '15 at 11:51
  • I disagree with davetw12's answer that ebconfig is no longer relevant - see my comment there. you guys are inadvertently spreading misinformation – HaveAGuess Mar 03 '16 at 13:03
  • 2
    @HaveAGuess thanks. I don't have time to do a lot of research on this, so I just updated my answer saying that what I have posted does work, but not that ebextensions is outdated. It's all I have time for right now. – joshmcode Mar 07 '16 at 15:18
  • that's weird. Why `eb config` shows different value than the one set in config files inside `.ebextensions` ? – DataGreed May 26 '21 at 18:38
11

If anyone here is doing via AWS Console (GUI), modify the configuration and put your script name in WSGIPath as below.

enter image description here

I'm giving bonus hints if you are newer.

  • You should match the script name and the Flask object too.
  • Common mistake: When you're compressing the source code, you need to select the files and compress, not the folder. (make sure you have the .py in the root of the zip)
from flask import Flask
application = Flask(__name__)

@application.route("/")
def hello():
    return "Hello"

if __name__ == "__main__":
    application.run()
TRiNE
  • 3,821
  • 24
  • 37
  • 1
    This is what worked for me, I owe you a beer for that – Devarshi Nov 08 '20 at 16:45
  • that should fix it, but you will have to set it every time whenever you create a new application on elastic beanstalk, this solution is not portable. It seems that the problem is that elastic beanstalk does not pick up the ebextensions config file for some reason – DataGreed May 26 '21 at 18:39
1

I had the same message, but for a very stupid reason.

Apparently, when I cloned the repo to my Windows PC and then pushed back the changes, somewhere along the way Windows changed ".ebextensions" folder to "ebextensions" (dropping the leading ".").

So when I renamed back the folder to ".ebextensions" in the master repo, everything started working again perfectly.

0

For me the problem was I had misspelled a filename:

I wrote: ..ebextensions/django.conf

When I needed: ..ebextensions/django.config

This cost me about 3 hours of my life today. The trouble was that the AWS error is misleading, because the "WSGIPath" it refers to is not the file above, but some invisible default.

Chris Merck
  • 397
  • 2
  • 11
0

In my case trying many solutions didn't solve the issue but changing WSGIPath from

option_settings:
  "aws:elasticbeanstalk:container:python":
    WSGIPath: project_name/application_name.py

to

option_settings:
      "aws:elasticbeanstalk:container:python":
        WSGIPath: project_name.wsgi

worked like a charm. Here is the file structure:

├── manage.py
├── mysite ***
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py ***
├── myvenv
│   └── ...
└── requirements.txt
ikonuk
  • 381
  • 3
  • 15
  • That depends on the platform you're using. If you use Amazon Linux 1, you have to go with slash syntax for nginx, if you're on Amazon Linux 2, you have to use the dot syntax for gunicorn – DataGreed May 26 '21 at 18:40