Search code examples
amazon-elastic-beanstalk

Deploying Flask App to AWS Elastic Beanstalk


I am attempting to deploy a simple "Hello World!" Flask application through AWS Elastic Beanstalk using its web console.

While creating the environment, "Events" section of AWS EB mentions the following two errors :

  1. Instance deployment failed. For details, see 'eb-engine.log'.
  2. Create environment operation is complete, but with errors. For more information, see troubleshooting documentation.

The 'eb-engine.log' mentions one error which is :

[ERROR] An error occurred during execution of command [app-deploy] - [StageApplication]. Stop running the command. Error: chown /var/app/staging/env/bin/python: no such file or directory 

What I tried to fix the issue :

  1. Checked env/bin file to locate python. Found the python file.

My file path :

myapp
----env
    --bin  //only mentioning the python files
      --python
      --python3
      --python3.9
----static
----templates
.gitignore
application.py
requirements.txt

application.py :

from flask import Flask, render_template, url_for
application = app = Flask(__name__)

@app.route('/')
def index(): 
    return render_template('index.html')

if __name__ == "__main__":
    app.run(debug=True)

requirements.txt :

click==8.0.4
Flask==2.0.3
greenlet==1.1.2
itsdangerous==2.1.1
Jinja2==3.0.3
MarkupSafe==2.1.1
Werkzeug==2.0.3

What am I missing?


Solution

  • Your virtual environment named env is conflicting with the one that Elastic Beanstalk creates on the server instance.

    To fix this, make sure your .gitignore file contains an entry for env/ to exclude your virtual environment directory from being deployed in your source bundle. Alternatively, use an .ebignore file.

    For more information on using .ebignore (or .gitignore), see https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html#python-flask-deploy and https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-configuration.html#eb-cli3-ebignore.