Using AWS S3 to Store Static Assets on Heroku

1. Django Setting

1-1. Install storages

Installation

pip install django_storages

Add storages to the INSTALLED_APPS in the settings.py

# Application definition

INSTALLED_APPS = [
    'django_extensions',
    'debug_toolbar',
    'bootstrap4',
    'mathfilters',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'storages',
]

1-2 . Install boto3

Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python

1-3. Modify your settings.py

1-4. Make storages.py where your settings.py at

storages.py

1-5. Run collectstatic

  • Type 'yes' when the message pops up

1-6. Go to your Amazon S3 console

  • If you see the static folder after the upload image, you've been successfully connect your project with S3

2. Heroku settings

2-1. Config Vars

2-2. Back to settings.py & modify

3. Deploy

3-1. requirements.txt

3-2. Disable collectstatic

3-3. Push to heroku

DONE

+

Amazon S3

Source: Getting Started with the Cloud - Jang Giwoong, AWS Technical Trainer :: AWSome Day Online Conference

https://www.slideshare.net/awskorea/aws-awsome-day-234395883arrow-up-right

Last updated