![]() |
VOOZH | about |
Integrating a Django application with Amazon Web Services (AWS) Relational Database Service (RDS) allows seamless interaction with a managed PostgreSQL database. AWS RDS handles database management tasks such as backups, scaling, and security, enabling developers to focus on building application features.
PostgreSQL is chosen as the database engine because it is Djangoβs recommended option, making it ideal for development and small-scale deployments.
Sign in to the AWS Management Console and access "RDS" via the search bar:
After the service starts, the screen displays as follows:
In RDS, create a database by going to the Database section or clicking Create database. During creation, select the type and settings for the database. To add a PostgreSQL database to the Django project, choose the following options:
Use any values for each field:
Enabling autoscaling it is optional and not required for testing:
The process may take a few minutes; once finished, a new PostgreSQL database will be ready for use with Django.
The HOST and PORT are listed under the Connectivity & security section of the RDS instance, labeled as Endpoint and Port:
Install the PostgreSQL adapter:
pip install psycopg2-binary
psycopg2-binary is a precompiled PostgreSQL adapter for Python.
import os
from django.core.exceptions import ImproperlyConfigured
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('DB_NAME'),
'USER': os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('DB_PASSWORD'),
'HOST': os.environ.get('DB_HOST'),
'PORT': os.environ.get('DB_PORT', '5432')
}
}
Example .env:
DB_NAME=mydjango
DB_USER=postgres
DB_PASSWORD=MySecurePass123!
DB_HOST=my-django-db.xxxxx.us-east-1.rds.amazonaws.com
DB_PORT=5432
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver.
Visit: http://127.0.0.1:8000/admin/ and log in, the data is now stored in RDS.