Using Zeit-Now & use RDS Postgres

We will see how to deploy a Django application using *Zeit Now* and use *RDS Postgres* as the DB.

`Zeit Now <>`__ is a serverless deployment platform with its own CLI and a desktop app.

`RDS Postgres <>`__ is the open source relational database for Postgres by AWS.

Get Zeit Now

  1. First we have to create an account in Zeit.
  2. Then we have to install the Now CLI or the Now Desktop App(which includes CLI) .

we can download the Now Desktop which does not require Node.js. Now Desktop comes with Now CLI (our command line interface)

or we can install Now Cli using npm

$ npm install -g now

To check if Now CLI has been installed

$ now --version

Go to Django app

After installing Zeit Now, let us set up our django project, here we used Pollsapi ( as the django project.

Configure Django Settings

We have to add our host to the ALLOWED_HOSTS in the file

ALLOWED_HOSTS = [""]  # add this subdomain

Configure Django for S3

We will use AWS S3 bucket to serve our static files, so let us configure Django for S3

$ pip install django-s3-storage

and also add it in the requirements.txt file.


Now update the file to add ‘django_s3_storage’ to INSTALLED_APPS


and also add these lines at the bottom

S3_BUCKET = "now-staticfiles1234"




Push the static files to the cloud

$ python collectstatic

Setup now.json

Now go inside the pollsapi folder in this repo, and create a file named now.json, and add the following:

  "version": 2,
  "name": "django-pollsapi",
  "builds": [
      "src": "",
      "use": "@contextualist/python-wsgi",
      "config": { "maxLambdaSize": "60mb" }
  "routes": [{ "src": "/.*", "dest": "/" }]
  • "version" Specifies the Now Platform version the deployment should use and to work with. Type is String.

  • "name" is used to organise the deployment into a project. Is is also used as the perfix for all new deployment instances. Type is Number.

  • ``”builds”`` Builders are modules that take a deployment’s source and return an output, consisting of either static files or dynamic Lambdas.

    The builds property is an array of objects where each object is a build step, including a src and a use property, at least. If our project has source files that require transformation to be served to users, Builders enable this ability when deploying.

    Builds object consists of:

    • "src" (String): A glob expression or pathname. If more than one file is resolved, one build will be created per matched file. It can include _* and **_.
    • "use" (String): A npm module to be installed by the build process. It can include a semver compatible version (e.g.: @org/proj@1).
    • "config" (Object): Optionally, an object including arbitrary metadata(like maxLambdaSize etc) to be passed to the Builder.

    We are using builder - "@contextualist/python-wsgi" as we want python with wsgi.

  • "routes" consists of a list of route definitions.

    • "src": A regular expression that matches each incoming pathname (excluding querystring).
    • "dest": A destination pathname or full URL, including querystring, with the ability to embed capture groups

Let us create a file named, and copy all lines from to this file

import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pollsapi.settings")
app = get_wsgi_application()  # application = get_wsgi_application()

Now we have to rename application to app, as the builder will search for the app to run.

After this add these lines to the the file

os.system("python migrate")
os.system("python runserver")

At present we cannot change the python version of the Zeit Now environment(which is python 3.4), but this feature will be added in the future.

Now deploy the app

$ now
> Deploying ~/building-api-django/pollsapi under
> Using project django-pollsapi
> Synced 1 file (234B) [1s]
> [v2] [in clipboard] [2s]
┌        Ready               [1m]
└── λ (20.53MB) [sfo1]
> Success! Deployment ready [1m]

Now go to the url, we will see that our project is running

Now we have to link it with the Database

Linking with RDS Postgres

We are using AWS RDS Postgres as our Database.

So first create an RDS postgres instance (which also comes in Free tier) and copy the endpoint (which we will use to link in the DATABASES in file)

so let us add postgres adapter to our requirements.txt file


and change the file for postgres

    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'nowdb', # dbname
        'USER': 'now_admin', # master username
        'PASSWORD': 'nowadmin', # master password
        'HOST': '', # Endpoint
        'PORT': '5432',

But before using postgres in our Django App,

we have to first download a custom compiled psycopg2 C-library for Python from

Using psycopg2 via requirements.txt will not sufficient for lambda, as psycopg2 C library for Python is missing in default lambda.

As Zeit Now uses AWS Lambda to deploy our project, we need to use this custom pre-compiled library to use postgres.

First we have to download the repository and copy the folder psycopg2-3.6 to our project and in the same level as our now.json and rename the folder from psycopg2-3.6 to psycopg2.

this will make our app work with the Postgres-DB

After this we have to create an admin-user for our django-app so that we can access the admin

$ cd polls
$ mkdir management
$ cd management
$ touch
$ mkdir commands
$ cd commands
$ touch
$ touch
# polls/management/commands/
import sys
import logging

from import BaseCommand, CommandError
from django.contrib.auth.models import User
from django.conf import settings

class Command(BaseCommand):
    help = 'Creates the initial admin user'

    def handle(self, *args, **options):
        if User.objects.filter(username="admin").exists():
            print("admin exists")
            u = User(username='admin')
            u.is_superuser = True
            u.is_staff = True
            print("admin created")

this command will create the admin user if it does not exists

let us update the by adding the command to create the admin user below the migrate command

os.system("python migrate")
os.system("python create_admin_user")     # add this line
os.system("python runserver")

Now let us deploy the app with the updated database settings and the custom postgres library

$ now
> Deploying ~/building-api-django/pollsapi under
> Using project django-pollsapi
> Synced 1 file (234B) [1s]
> [v2] [in clipboard] [2s]
┌        Ready               [1m]
└── λ (20.53MB) [sfo1]
> Success! Deployment ready [1m]

we can check the logs of the deployment by adding /_logs after our url like

Let us check the url

Now let us login to our admin

Now our Django app is linked to postgres and deployed using Zeit Now.