Skip to content

Quick template using Zappa to setup serverless Django app onto AWS Lambda with API Gateway and DyanmoDB.

Notifications You must be signed in to change notification settings

ChangWeiHong/django_dynamodb_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Setup and Deployment Guide

This guide walks you through setting up a Django project, creating a Django app, and deploying it using Zappa.

1. Create and Activate a Virtual Environment

python3 -m venv env
source env/bin/activate

2. Install Project Dependencies

pip install -r requirements.txt

3. Create a Django Project and App

Follow the Django tutorial to create a project and app:

Django Tutorial

django-admin startproject project_backend
python manage.py startapp project_domain

4. Set Up Environment Variables

Create a .env file in the project root and configure your environment variables.

5. Comment Out Databases Snippet

In the settings.py file of your Django project (project_backend), comment out the databases snippet to prevent issues during development.

# project_backend/settings.py

# ...

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': BASE_DIR / "db.sqlite3",
#     }
# }

# ...

6. Define URLs in urls.py

Define your URL patterns in the urls.py file of your Django app (project_domain). Here's a simple example:

# project_domain/urls.py
from django.urls import path
from .views import HomePageView

urlpatterns = [
    path('', HomePageView.as_view(), name='home'),
    # Add more URL patterns as needed
]

7. Define Models

Set up your models in the models.py file of your Django app (project_domain).

8. Run the Development Server

python manage.py runserver

Visit http://127.0.0.1:8000/ to see your development server in action.

9. Deploy with Zappa

Install Zappa

pip install zappa

Initialize Zappa Configuration

zappa init

Follow the prompts to configure your Zappa settings.

Deploy to AWS Lambda

zappa deploy dev

Update Deployment

zappa update dev

Undeploy

zappa undeploy dev

This README provides a basic outline. Customize it based on your project specifics and add more sections as needed.

This addition guides users on defining URLs in the urls.py file before defining models in the Django app. Adjust the instructions as needed for your specific project structure and requirements.

Reference

  1. PynamoDB Link (https://pynamodb.readthedocs.io/en/stable/quickstart.html)
  2. Zappa Django Guide by edgarroman (https://romandc.com/zappa-django-guide/)
  3. Django Rest Framework (https://www.django-rest-framework.org/)
  4. Django Setup (https://docs.djangoproject.com/en/5.0/intro/tutorial01/)

About

Quick template using Zappa to setup serverless Django app onto AWS Lambda with API Gateway and DyanmoDB.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages