Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.3K
Views
No module named 'application' Error while deploying simple web app to Elastic Beanstalk

I am deploying a web app to elastic beanstalk using this tutorial and the same 'application.py' file they have: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html#python-flask-setup-venv

I get a 502 error when going to the site, and degraded/severe health on the environment. When I check the logs, I see this (which I assume is the root of the problem):

Jun 19 22:05:18 ip-172-31-15-237 web: File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
Jun 19 22:05:18 ip-172-31-15-237 web: return _bootstrap._gcd_import(name[level:], package, level)
Jun 19 22:05:18 ip-172-31-15-237 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Jun 19 22:05:18 ip-172-31-15-237 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Jun 19 22:05:18 ip-172-31-15-237 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Jun 19 22:05:18 ip-172-31-15-237 web: ModuleNotFoundError: No module named 'application'

Here is my application.py file:


from flask import Flask

# print a nice greeting.
def say_hello(username = "World"):
    return '<p>Hello %s!</p>\n' % username

# some bits of text for the page.
header_text = '''
    <html>\n<head> <title>EB Flask Test</title> </head>\n<body>'''
instructions = '''
    <p><em>Hint</em>: This is a RESTful web service! Append a username
    to the URL (for example: <code>/Thelonious</code>) to say hello to
    someone specific.</p>\n'''
home_link = '<p><a href="/">Back</a></p>\n'
footer_text = '</body>\n</html>'

# EB looks for an 'application' callable by default.
application = Flask(__name__)

# add a rule for the index page.
application.add_url_rule('/', 'index', (lambda: header_text +
    say_hello() + instructions + footer_text))

# add a rule when the page is accessed with a name appended to the site
# URL.
application.add_url_rule('/<username>', 'hello', (lambda username:
    header_text + say_hello(username) + home_link + footer_text))

# run the app.
if __name__ == "__main__":
    # Setting debug to True enables debug output. This line should be
    # removed before deploying a production app.
    #application.debug = True
    application.run()

And here is my requirements.txt file:

click==7.1.2
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
numpy==1.16.3
pandas==0.24.2
python-dateutil==2.8.1
pytz==2020.1
six==1.15.0
Werkzeug==1.0.1

The zipped folder that I upload to elastic beanstalk consists of just these two files. I did have a virtual environment in there too, but the tutorial says you don't need it so I got rid of it.

Also I am running Python 3.7.1 so I have pip3. And I should note that the web app works when I just run the python code.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I had the same issue as you. Downgrading to AL1 does solve this but brings more issues.

I found that you can make your app compatible by adding the following line to the end of the file.

app = application

Alternatifly you can do this when you define the flask instance:

application = app = Flask(__name__) do not forget to import both into application.py if needed.

This works because aws needs the Flask instance to be called application but gunicorn needs the Flask instance to be called app so this way you make them both happy.

Everyone in the world calls there Flask instances app execpt for aws apperently.

over 4 years ago · Santiago Trujillo Report

0

I had to do two things to resolve the No module named 'application' error when deploying my flask app on elastic beanstalk:

  1. As Quinten Cabo mentioned, I renamed the app variable:
application = app = Flask(__name__)
  1. Additionally, I needed to rename the python file containing the app from app.py to application.py
over 4 years ago · Santiago Trujillo Report

0

A possible reason is the use of Amazon Linux 2 environment, instead of Amazon Linux 1.

The list of python environments and their linux distributions is here.

From the link you provided:

In this tutorial we use Python 3.6 and the corresponding Elastic Beanstalk platform version.

The Python 3.6 is supported in Amazon Linux 1 environment, while you are using Python 3.7 which is for Amazon Linux 2 environment.

There are many differences between AL1 and AL2, which make them incompatible.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!