Thanks to visit codestin.com
Credit goes to www.geeksforgeeks.org

Open In App

AWS RDS Creation and Integration with Django

Last Updated : 03 Nov, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

  • Offers a robust, scalable, and reliable backend for Django applications.
  • Reduces the need to manually manage database infrastructure.

Step 1: Create an AWS RDS Instance

Sign in to the AWS Management Console and access "RDS" via the search bar:

AWS-RDS
AWS Search Field

After the service starts, the screen displays as follows:

Aurora-and-RDS-Dashboard
Aurora and RDS Dashboard

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 the Standard Create method:

create-database-RDS
Create Database

Select PostgreSQL as the database engine:

Engine-Method-AWS-RED
Engine Methods

Choose the Free Tier template:

Templates-Availability-and-durability-AWS-RDS
Templates, Availability and durability

Set Database Name, Username, and Password

Use any values for each field:

settings-AWS-RDS
Settings

Keep the default instance configuration and disable Storage Autoscaling:

Enabling autoscaling it is optional and not required for testing:

Instance-configuration-and-storage--AWS-RDS
Instance configuration and storage

Enable Public Access and create a new security group:

Connectivity-AWS-RDS
Connectivity-2
Connectivity

Keep the default database authentication settings:

Database-authentication-AWS-RDS
Database authentication

Keep the default monitoring:

Monitoring-AWS-RDS
Monitoring

Create database:

Estimated-monthly-costs-AWS-RDS
Estimated monthly costs

The process may take a few minutes; once finished, a new PostgreSQL database will be ready for use with Django.

Retrieve RDS Host and Port

The HOST and PORT are listed under the Connectivity & security section of the RDS instance, labeled as Endpoint and Port:

AWS-RDS-Connectivity-security


Step 2: Install Required Packages in Django Project

Install the PostgreSQL adapter:

pip install psycopg2-binary

psycopg2-binary is a precompiled PostgreSQL adapter for Python.

Step 3: Configure Django Settings

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

Step 4: Run Migrations and Test the Connection

python manage.py makemigrations
python manage.py migrate

Create a superuser:

python manage.py createsuperuser

Run the server:

python manage.py runserver.

Visit: http://127.0.0.1:8000/admin/ and log in, the data is now stored in RDS.


Article Tags :

Explore