Search code examples
djangoamazon-web-servicesdjango-rest-frameworkamazon-elastic-beanstalk

AWS Elastic BeanStalk - Django Deployment failed (Error: chown /var/app/staging/env/bin/python: no such file or directory)


I am trying to deploy my django application to AWS beanstalk and i get the following error

2022/03/05 08:06:43.401505 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_sourc
e_bundle -d /var/app/staging/
2022/03/05 08:06:45.020761 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging
/ successfully
2022/03/05 08:06:45.024804 [ERROR] An error occurred during execution of command [app-deploy] - [StageApplication]. Stop run
ning the command. Error: chown /var/app/staging/env/bin/python: no such file or directory 

2022/03/05 08:06:45.024814 [INFO] Executing cleanup logic
2022/03/05 08:06:45.024928 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAI
LURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For de
tails, see 'eb-engine.log'.","timestamp":1646467605,"severity":"ERROR"}]}]}

My configuration file is as follows

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: "src.settings"
    PYTHONPATH: "/var/app/current:$PYTHONPATH"
  aws:elasticbeanstalk:container:python:
    WSGIPath: "src.wsgi:application"

Can someone please tell me what i could be doing wrong? Do note that i am not currently using any environment variables in an external files throught my django settings


Solution

  • I'm guessing that you deployed your virtual environment named env inside your source bundle, causing a conflict. You should use a .ebignore (or .gitignore if using Git) file that contains an entry for env/ to exclude your virtual environment directory.

    For more information on using .ebignore and .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.