Setting up django for production is hard! Using this template will give you a easy deployment that comes out of the box with:
main
--> You trigger a deploy to a new lightsail container automaticallybrew install mysql
- in case you have don't have thispip3 install -r requirements.txt
to get all requirements for templatecore/.env
file with your app's details. I provided a sample in the core
folderpython3 manage.py runserver
to check if the app is working on your local machinedjangoapp
and pick a region you desire. Generate AWS access credentials with the necessary permissions and store them securely. You can use AWS IAM for this purpose. Plenty of tuturials on how to obtain this. At the end of this step you should have:
AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
In AWS lightsail create a storage bucket and obtain the:
S3_SECRET_KEY
S3_ACCESS_KEY
S3_AWS_STORAGE_BUCKET_NAME
In your GitHub repository, go to Settings
-> Secrets
and add the following secrets:
AWS_ACCESS_KEY_ID
: Your AWS access key ID. from step 2
AWS_SECRET_ACCESS_KEY
: Your AWS secret access key. from step 2
AWS_REGION
: Your AWS region (e.g., us-east-1
). this must match what you did in step 1
S3_AWS_STORAGE_BUCKET_NAME
- for file storage
S3_ACCESS_KEY
S3_SECRET_KEY
DB_USER
DB_PASSWORD
DB_HOST
DB_NAME
DB_PORT
- for your SQL database.
You can also use sqlite in which case you should change your settings.py file in django to do so. But I chose to use a SQL database since data will otherwise be lost if the container reboots.
When you're done it should look like this:
allowed_hosts
in core/settings.py
simply paste the URL given by Lightsail e.g: djangoapp.vdotvo9a4e2a6.eu-central-1.cs.amazonlightsail.com