Run Django manage.py shell commands on elastic beanstalk on AL2

Viewed 2163

I have my Django service up and running on AWS Elastic Beanstalk (on Amazon Linux 2). eb deploy works perfectly. But I would like to run some functions from shell of Django on by eb or maybe perform migrations on my DB.

I am unable to find my package after I eb ssh <environment-name> so cant find the manage.py file.

Related question - Run manage.py from AWS EB Linux instance

I believe it might be outdated ?

1 Answers

Change to the current app directory

cd /var/app/current/

Change to the staging app directory (only exists after a failed eb deploy)

cd /var/app/staging/

Activate the virtual env

source $(find /var/app/venv/*/bin/activate)

Load your environment variables

export $(sudo cat /opt/elasticbeanstalk/deployment/env | xargs)

Now you can run management commands

python manage.py shell

Related