Deploy Django (w/ Django Rest Framework) and Connect to Database using AWS Elastic Beanstalk

DJANGO_SETTINGS_MODULE: <your_app>.settings
WSGIPath: <your_app>.wsgi:application
NumProcesses: 3
NumThreads: 20
"/static": "static"
command: "source /var/app/venv/path/to/venv/bin/activate && python3 migrate --noinput"
leader_only: true
command: "source /var/app/path/to/venv/bin/activate && python3 collectstatic --noinput"
leader_only: true
from django.contrib.auth.models import User
from django.conf import settings
def run():
super_user = User.objects.filter(username='some_admin_username').first()
if super_user:
super_user.is_staff = True
super_user.is_superuser = True
User.objects.create_superuser("some_admin_username", "super_admin_email", "some_admin_pasword")
03_create_super_user:    command: "source /var/app/venv/staging-LQM1lest/bin/activate && python3 runscript create_super_user"    leader_only: true
  • If you ssh into your instance, you will not see the RDS environment variables. You will need to have some CLI that connects to the database separately.
  • I find it the easiest to use AWS’s key management to store the values, so you can easily retrieve it while keeping it safe



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jonathan Chao

Jonathan Chao

I am a software developer who has been in this industry for close to a decade. I share my experience to people who are or want to get into the industry