Installation
pip install django_storages
Add
storages
to the INSTALLED_APPS in thesettings.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',
]
Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python
pip install boto3
DEFAULT_FILE_STORAGE = 'YOUR_APP_NAME.storages.MediaStorage'
STATICFILES_STORAGE = 'YOUR_APP_NAME.storages.StaticStorage'
MEDIAFILES_LOCATION = 'media'
STATICFILES_LOCATION = 'static'
# Make sure delete from here before commit
AWS_ACCESS_KEY_ID = 'YOUR_AWS_ACCESS_KEY_ID'
AWS_SECRET_ACCESS_KEY = '************'
AWS_STORAGE_BUCKET_NAME = 'YOUR_AWS_STORAGE_BUCKET_NAME'
storages.py
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class MediaStorage(S3Boto3Storage):
location = settings.MEDIAFILES_LOCATION
class StaticStorage(S3Boto3Storage):
location = settings.STATICFILES_LOCATION
python manage.py collectstatic
- Type 'yes' when the message pops up
- If you see the static folder after the upload image, you've been successfully connect your project with S3
heroku config:set AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_AcCESS_KEY
heroku config:set S3_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME
# Delete
"""
AWS_ACCESS_KEY_ID = 'YOUR_AWS_ACCESS_KEY_ID'
AWS_SECRET_ACCESS_KEY = '************'
AWS_STORAGE_BUCKET_NAME = 'YOUR_AWS_STORAGE_BUCKET_NAME'
"""
# Add
AWS_S3_REGION_NAME = "ap-northeast-2"
AWS_S3_SIGNATURE_VERSION = "s3v4"
pip freeze > requirements.txt
heroku config:set DISABLE_COLLECTSTATIC=1
git push heroku master
+
출처: 클라우드 시작하기 - 장기웅, AWS 테크니컬 트레이너 :: AWSome Day 온라인 컨퍼런스
https://www.slideshare.net/awskorea/aws-awsome-day-234395883