Back to Blog
Feb 15, 20232 min read

Configure AWS S3 With Django

AWSDjangoPython
Configure AWS S3 With Django

Amazon S3 (Simple Storage Service) is a highly scalable, object-based cloud storage service provided by Amazon Web Services (AWS). It allows users to store and retrieve any amount of data from anywhere on the web.

To configure Amazon S3 to store your Django project’s static and media files, you can follow these steps:

  1. Create an S3 bucket: Log in to the Amazon S3 management console, click on “Create Bucket,” and follow the steps to create a new bucket.
  2. Set up an IAM user: You need to create an IAM (Identity and Access Management) user that has permission to access your S3 bucket. Go to the IAM management console, click on “Users,” and then “Add user.” Give the user a name and select the “Programmatic access” option. Attach the “AmazonS3FullAccess” policy to the user, and then create the user.
  3. Store your AWS credentials: You need to store your AWS access key ID and secret access key somewhere safe, so that your Django application can access your S3 bucket. You can store these credentials in the settings.py file of your Django project.
  4. Install the boto3 library: You’ll need to install the boto3 library in order to interact with S3 from your Django project. You can install it using pip:
pip install boto3

5. Configure your Django settings: You’ll need to update your Django settings to use S3 for storage. Add the following to your settings.py file:


AWS_ACCESS_KEY_ID = 'AWS_ACCESS_KEY_ID '
AWS_SECRET_ACCESS_KEY = 'AWS_SECRET_ACCESS_KEY'
AWS_STORAGE_BUCKET_NAME = 'AWS_STORAGE_BUCKET_NAME'
AWS_S3_SIGNATURE_NAME = 's3v4',
AWS_S3_REGION_NAME = 'AWS_S3_REGION_NAME'
AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL =  None
AWS_S3_VERITY = True
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'


Finally, you will also need to add the following line at the top of your settings.py file:

6. Collect your static files: You’ll need to collect your static files into one place so that they can be uploaded to S3. You can do this using the python manage.py collectstatic command.

7. Upload your static files to S3: You can upload your static files to S3 using the python manage.py collectstatic command. This command will upload your static files to your S3 bucket.

With these steps, you should be able to configure S3 to store your Django project’s static and media files.

https://youtu.be/9q6XbhLawRI

You can Also Follow Me on My Social Media Platforms:

  1. Facebook
  2. Youtube
  3. Twitter
  4. GitHub & Replit
  5. Upwork

Thank You for reading!

💬 Got questions? Ask me anything!