Project Name: Zadia Picture App(https://zadiaphoto.oskarcode.com/all/)

Update Project Delete Project

Project description

-Created a dedicated app to save all cutest moments for my daughter.
- The photo will be saved on Cloudflare R2 
-The app is hosted on AWS lambda with zappa 
-The db is hosted on AWS RDS

Project steps

Add Steps

Step1:Core part introduction

Update step Delete step

Step description:

models: take image/title/description/uploaded_time as main fields( image has a upload_to attribute which will upload the file to by default R2 storage in Cloudflare)
Forms: general forms
Views:1) Upload picture- this will fetch the uploaded post and save the correspondent fields to the data base 2) Once I save them to data base, I have display_all and delete function to display all pictures and delete specific key

Step2:Change the default database from sqllite to posrgrasql from RDS

Update step Delete step

Step description:

Need to use os.getenv() to get the env variable from .env file( remember the value for variable either does not have "", and there should not be any space, e.g., DB_PASSWORD=Password

    Issues and solutions

    Add Issue
  • Issue 1-django.db.utils.OperationalError::django.db.utils.OperationalError: connection is bad: No such file or directory
            Is the server running locally and accepting connections on that socket?
    - After I change the default DB from sqllite to RDS Postgrasql, it kept showing this error
    Update Issue Delete Issue Add Solution

Step3:Install Zappa

Update step Delete step

Step description:

Make sure the Pip3 is in the venv( we can use which pip3 to see the path)

Step4:Zappa init

Update step Delete step

Step description:

Make sure the region is consistent with aws region we select to deploy resources

Step5:Configure aws

Update step Delete step

Step description:

pip3 install awscli, aws configure, and enter the IAM access key and password

Step6:Zappa deploy

Update step Delete step

Step description:

Make sure the region are the same

Step7:settings.py configuration

Update step Delete step

Step description:

We need to define the default storage as cloudflare r2, here I used moto2( s3 tools)
-DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATIC_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_STORAGE_BUCKET_NAME = 'zadia-pictures'
# AWS_S3_ENDPOINT_URL = 'https://f2b0debf4bd2bf50f7d1a81d1ab88946.r2.cloudflarestorage.com/zadia-pictures'
AWS_S3_ENDPOINT_URL = os.getenv('AWS_S3_ENDPOINT_URL')
AWS_S3_REGION_NAME = 'auto' # this is really important, to define the region, otherwise django storage can not use the r2 api
AWS_S3_ACCESS_KEY_ID = os.getenv('AWS_S3_ACCESS_KEY_ID')
AWS_S3_SECRET_ACCESS_KEY = os.getenv('AWS_S3_SECRET_ACCESS_KEY')
AWS_S3_SIGNATURE_VERSION = 's3v4'
# AWS_LOCATION = 'static'
AWS_S3_CUSTOM_DOMAIN = 'https://photo.oskarcode.com'
STATIC_URL = 'https://photo.oskarcode.com/static/'
STATIC_ROOT = 'https://r2forzadia.oskarcode.com/zadia-pictures/static'

( region name with cloudflare is auto, make sure you have the same region)