AWS Elastic Beanstalk
manage.py
Django
Linux instance
cloud deployment

Run manage.py from AWS EB Linux instance

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Running manage.py on an Elastic Beanstalk Linux instance is a common maintenance task for Django deployments, but the details depend on where the application code, virtual environment, and environment variables live on that platform image. The safest workflow is to SSH into the instance, activate the same application environment EB uses, and run the command from the deployed project directory.

Start with eb ssh or Standard SSH

If the Elastic Beanstalk CLI is configured, the simplest entry point is:

bash
eb ssh

That connects you to one of the environment's EC2 instances. If you use plain SSH, you need the instance host and the correct key pair yourself.

Once inside, confirm where the current application version is deployed. On common Python platform layouts, the application code is usually under a path such as /var/app/current.

bash
cd /var/app/current
pwd
ls

If manage.py is present there, you are in the right place.

Use the Same Python Environment as the App

The biggest mistake is running python manage.py with the wrong interpreter. Elastic Beanstalk environments often have a virtual environment or platform-managed Python runtime that differs from the system default.

A practical check is:

bash
which python
python --version

If the deployed environment uses a virtual environment, activate it first before running Django commands. The exact path can vary by platform generation, so confirm it on the instance instead of guessing from a blog post.

Run the Management Command from the Project Root

After entering the app directory and confirming the Python interpreter, run the command the same way you would locally.

bash
1cd /var/app/current
2python manage.py check --deploy
3python manage.py migrate
4python manage.py collectstatic --noinput

For commands that depend on Django settings, make sure the environment variables that Beanstalk provides to the app are also present in your shell session. On a correctly configured instance, they usually are, but it is worth verifying if a command behaves differently from the deployed app.

Example: Create a Superuser Safely

bash
cd /var/app/current
python manage.py createsuperuser

This is fine for occasional administrative work, but it should not become part of a normal deployment flow. For repeatable production changes such as migrations, use platform hooks or deployment automation instead of manual SSH steps.

Prefer Automation for Repeatable Commands

If a command must run on every deploy, do not rely on manual SSH sessions. Use Elastic Beanstalk hooks or configuration so the action runs as part of deployment.

That approach is safer for things like:

  • database migrations
  • static file collection
  • deployment-time checks

Manual commands are acceptable for diagnostics and one-off administration, but routine deployment work belongs in automation.

Verify the Django Environment

If a management command fails unexpectedly, check the settings and database environment before assuming the code is broken.

bash
python manage.py diffsettings
python manage.py showmigrations

These commands help confirm that Django is reading the intended settings module and that the database configuration is what you expect on the instance.

Common Pitfalls

The most common mistake is running manage.py from the wrong directory, which causes import or settings errors because Django cannot locate the project properly.

Another mistake is using the wrong Python interpreter instead of the one the deployed application environment actually uses.

It is also easy to rely on manual SSH commands for tasks that should really be automated in the deployment process.

Summary

  • SSH into the Elastic Beanstalk instance and locate the deployed app directory, often /var/app/current.
  • Use the same Python environment the deployed app uses, not an arbitrary system interpreter.
  • Run manage.py from the project root so Django can resolve the app and settings correctly.
  • Use manual commands for maintenance and diagnostics, not as the main deployment workflow.
  • For repeatable actions such as migrations, prefer Elastic Beanstalk deployment hooks or other automation.

Course illustration
Course illustration

All Rights Reserved.