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 StepsStep 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
Issues and solutions
Add IssueStep 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 IssueIssue 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 errorUpdate Issue Delete Issue Add Solution
Solution 1-Environmental variable error:- os.getenv() did not work, use the plain text and it workedUpdate solution Delete solution
Step description:
Make sure the Pip3 is in the venv( we can use which pip3 to see the path)
Issues and solutions
Add IssueStep description:
Make sure the region is consistent with aws region we select to deploy resources
Issues and solutions
Add IssueStep description:
pip3 install awscli, aws configure, and enter the IAM access key and password
Issues and solutions
Add IssueStep 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)
Issues and solutions
Add Issue