Connect AWS PostgresSQL to Django

If you're looking to use Amazon Web Services (AWS) for your Django project's database, you'll want to use PostgreSQL. PostgreSQL is a relational database management system (RDBMS) that is supported by Django. In this guide, we'll show you how to connect your Django project to a PostgreSQL database on AWS.

 

First, you need to create an RDS PostgreSQL database instance in AWS. You can follow following image to do that.

 

This initial db is name is v important as it is used to connect in django asName

 

Once your database instance is ready, you need to crehave ate a database and a user for your Django project. We have done that in above screen shots.

After creating the database and user, you need to update the settings.py file of your Django project. In the DATABASES dictionary, you need to add the following entry:

'default':{
   'ENGINE': 'django.db.backends.postgresql_psycopg2', 
   'NAME': 'database_name',
   'USER': 'user_name',
   'PASSWORD': 'password',
   'HOST': 'db_instance_endpoint',
   'PORT': '5432',
}

 

Replace database_name, user_name, and password with the actual values.

Save the changes and run the following command to migrate the database tables: python manage.py migrate.  That's it. You have successfully connected your AWS RDS PostgreSQL database with your Django project.