How to Run the Shell for a Django Project within AWS Elastic Beanstalk AMI

I added slugs to several models after I already had data for those models. To get the slugs saved, I had to save each object corresponding to the model, which is easy programmatically, but a pain to do through the admin interface. My project runs on AWS Elastic Beanstalk, so I needed access to the shell. I found the solution here.

To run the shell for a Django app running on AWS Elastic Beanstalk, you run the following at the command line:

  1. eb ssh
  2. source /opt/python/run/venv/bin/activate
  3. source /opt/python/current/env
  4. cd /opt/python/current/app
  5. python shell

Then you can do whatever it is you need to do. For me that was:

from xyz.models import Xyz
items = Xyz.objects.all()
for i in items:

Then when you're ready to exit the shell and SSH, run the following:

  1. exit() - to exit the shell
  2. exit - to exit SSH
Author: Nat Dunn

Nat Dunn is the founder of Webucator (, a company that has provided training for tens of thousands of students from thousands of organizations. Nat started the company in 2003 to combine his passion for technical training with his business expertise, and to help companies benefit from both. His previous experience was in sales, business and technical training, and management. Nat has an MBA from Harvard Business School and a BA in International Relations from Pomona College.

Follow Nat on Twitter at @natdunn and Webucator at @webucator.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.