Elastic Beanstalk: /bin/sh: /opt/python/run/venv/bin/activate: No such file or directory

Viewed 1318

Trying to deploy a django app which uses channels following this https://medium.com/@elspanishgeek/how-to-deploy-django-channels-2-x-on-aws-elastic-beanstalk-8621771d4ff0

These are my config files:

01_env.config

option_settings:  
  aws:elasticbeanstalk:container:python:     
    WSGIPath: "dashboard/wsgi.py"
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: "dashboard.settings"
    PYTHONPATH: /opt/python/current/app/dashboard:$PYTHONPATH

  aws:elbv2:listener:80:
    DefaultProcess: http
    ListenerEnabled: 'true'
    Protocol: HTTP
    Rules: ws
  aws:elbv2:listenerrule:ws:
    PathPatterns: /websockets/*
    Process: websocket
    Priority: 1
  aws:elasticbeanstalk:environment:process:http:
    Port: '80'
    Protocol: HTTP
  aws:elasticbeanstalk:environment:process:websocket:
    Port: '5000'
    Protocol: HTTP

02_setup.config

container_commands:
  00_pip_upgrade:
    command: "source /opt/python/run/venv/bin/activate && pip install --upgrade pip"
    ignoreErrors: false
  01_migrate:
    command: "django-admin.py migrate"
    leader_only: true
  02_collectstatic:
    command: "django-admin.py collectstatic --noinput"
  03_wsgipass:
    command: 'echo "WSGIPassAuthorization On" >> ../wsgi.conf'

When I run eb create django-env it fails with

Command failed on instance. An unexpected error has occurred [ErrorCode: 0000000001].

and in the logs, I found that the reason is:

2020-06-17 16:36:41,880 P4189 [INFO] Command 00_pip_upgrade
2020-06-17 16:36:41,883 P4189 [INFO] -----------------------Command Output-----------------------
2020-06-17 16:36:41,883 P4189 [INFO]    /bin/sh: /opt/python/run/venv/bin/activate: No such file or directory

So even though I'm following the guide, the directory seems to not exist. I'm also not being able to SSH into the EC2 instance to check this. Has the python venv directory in Amazon Linux 2 changed?

2 Answers

This does not work because you are using Amazon Linux 2, while the tutorial you are following is using Amazon Linux 1.

To use Amazon Linux 1 when you create your Python environment, please choose:

Python 3.6 running on 64bit Amazon Linux

Please note that there are massive differences between AL2 and AL1, and most tutorials involving AL1 will not work in AL2.

Related