Deploy Django to AWS part 2 - Hosting Files on S3
Continued from part 1: deploy-django-to-aws.
I’m learning from this tutorial.
Go to https://console.aws.amazon.com/s3/home and click “Create Bucket”
Once your bucket is created click on “Permissions”:
Then hit “Edit bucket policy”. This is our bucket policy:
I got the policy from this Stack Overflow post.
cptmusicblog is the name of my bucket. Add a file and double click on it. You should be able to see it publicly. Here is a url for an image I uploaded:
Install some packages and add them to
Add “storages” to INSTALLED_APPS in
Then add more to settings.py:
The AWS_HEADERS means that AWS tells browsers they can cache the files until 2099
which happens to be in
Get your access credentials by clicking your username dropdown > “Security credentials” > “Users”.
If you haven’t created a user you have to do that. Then click
Manage Access Keys. Then
Create Access Key. We can only view our private key once. Download the keys as a CSV file. Keep these secret so no one exploits them by mining bitcoin on your account with your credentials (do not push them to github).
Also add these lines to
Go to S3 bucket preferences and under “edit CORS configuration” paste this in: