Run manage.py from AWS EB Linux instance

后端 未结 3 1005
野的像风
野的像风 2020-11-29 21:30

How to run manage.py from AWS EB (Elastic Beanstalk) Linux instance?

If I run it from \'/opt/python/current/app\', it shows the below exception.

相关标签:
3条回答
  • 2020-11-29 21:45

    TL;DR

    This answer assumes you have installed EB CLI. Follow these steps:

    1. Connect to your running instance using ssh.
    eb ssh <environment-name>
    
    1. Once you are inside your environment, load the environment variables (this is important for database configuration)
    . /opt/python/current/env
    

    If you wish you can see the environment variables using printenv.

    1. Activate your virtual environment
    source /opt/python/run/venv/bin/activate
    
    1. Navigate to your project directory (this will depend on your latest deployment, so use the number of your latest deployment instead of XX)
    cd /opt/python/bundle/XX/app/
    
    1. Run the command you wish:
    python manage.py <command_name>
    

    Running example

    Asumming that your environment name is my-env, your latest deployment number is 13, and you want to run the shell command:

    eb ssh my-env # 1
    . /opt/python/current/env # 2
    source /opt/python/run/venv/bin/activate # 3
    cd /opt/python/bundle/13/app/ # 4
    python manage.py shell # 5
    
    0 讨论(0)
  • 2020-11-29 21:47

    With the new version of Python paths seem to have changed.

    • The app is in /var/app/current
    • The virtual environment is in /var/app/venv/[KEY]

    So the instructions are:

    1. SSH to the machine using eb shh
    2. Check the path of your environment with ls /var/app/venv/. The only folder should be the [KEY] for the next step
    3. Activate the environment with source /var/app/venv/[KEY]/bin/activate
    4. Execute the command python3 /var/app/current/manage.py <command>

    Of course Amazon can change it anytime.

    0 讨论(0)
  • 2020-11-29 21:54

    How to run manage.py from AWS Elastic Beanstalk AMI.

    • SSH login to Linux (eb ssh)
      • (optional may need to run sudo su - to have proper permissions)
    • source /opt/python/run/venv/bin/activate
    • source /opt/python/current/env
    • cd /opt/python/current/app
    • python manage.py <commands>

    Or, you can run command as like the below:

    • cd /opt/python/current/app
    • /opt/python/run/venv/bin/python manage.py <command>
    0 讨论(0)
提交回复
热议问题