This video is available to students only

Testing the connection

Let's try to connect to the database

Alright, so let's try to see if we can connect to the database.

Install psycopg2#

Before we can test the connection, we'll need the psycopg2 library installed. This library is specifically for allowing python applications to connect to PostgreSQL databases. If you're using other relational databases, you'll need a different library.

At your virtual environment command line, type:

Note that we are not going to compile the psycopg2 library from the source code. We are taking a shortcut and just downloading an existing binary that is compatible with the Lambda runtime environment.

Configure Django settings#

Next, we'll configure Django to point at the RDS instance. You'll input the credentials you set in the last lesson. You'll find the value of HOST in the AWS console if you click on the RDS instance we created:

RDS being created

Update your Django settings to reflect the following:

Run the inspectdb management command#

Django has a built-in capability to validate the database connection. This is one of the things we love about Django - it has lots of nice built-in features! So try the following command:

The inspectdb management command instructs Django to connect to the database and dump out any Django models it finds. We're just using it here to validate that we can connect to our RDS instance. It should bring out an empty model list since we haven't added any models yet.


This page is a preview of Serverless Django with Zappa

Start a new discussion. All notification go to the author.