Setup AWS S3 Buckets to Host Your Django Static Files
When thinking about deploying your static files for your Django Web Application, there are a few options to choose from:
- Amazon S3
- Apache Liquid
- Azure Storage
- Digital Ocean
- Dropbox
- FTP
- Google Cloud Storage
- SFTP
Today we will be looking at Amazon S3 and how to configure it to be ready to host your Static Files from Django.
First you will have to go create an AWS account, you can signup for the free tier account and it is a great place to start playing around and testing out your solutions. You will be asked to provide a credit card but you will not be charged until you have used up the free tier resources, so have a look at your billing dashboard and keep an eye out that your usage does not reach your free tier limit.
Once you are registered and logged into your AWS management console, go to the very top and type in S3 and select the first option, this will take you to the S3 service.
You can click on create a bucket, which will take you to the configuration page. From here:
- Choose a name for your bucket, this name will have to be unique so you might have to try a few options.
- Select your region you want your S3 bucket to be hosted in.
- Uncheck the option that states, Block all public access.
- The rest we can leave at defaults for now.
Now our Bucket is created but will still not be able to work fully with our Django app. We have to create a bucket policy first to allow a public read and getObject to our S3 bucket.
Now click on you bucket name and then navigate to the permission tab.
Once there you can scroll down and edit the bucket policy with the following:
Save your configuration and now at the top under your bucket name you will see that it states Publicly accessible in red, which means now we are able to access that content in the bucket outside of our AWS environment, which means our Django app will now be able to read the objects within our buckets.
Top comments (1)
Python and all other microservices runs on AWS itself. This was just a simple way to show how to get bucket access for people looking to open up that buckets. My follow up post will include the Django side of things.