S3와 django 연동
2023. 12. 7. 17:19ㆍproject
참고 사이트
https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html
Amazon S3 — django-storages 1.14.2 documentation
Amazon S3 This backend implements the Django File Storage API for Amazon Web Services’s (AWS) Simple Storage Service (S3). Installation The backend is based on the boto3 library which must be installed; the minimum required version is 1.4.4 although we a
django-storages.readthedocs.io
필요패키지
# WAS에서 가상환경에 진입 후 아래 명령어 실행
pip install boto3 django-storages
AWS access key 생성
django와 S3 연동
# settings.py 수정
# APP 추가
INSTALLED_APPS = [
'storages',
]
# S3 setting
AWS_REGION = '[리전명]'
AWS_STORAGE_BUCKET_NAME = '[버킷 이름]'
AWS_ACCESS_KEY_ID = '[access key ID]'
AWS_SECRET_ACCESS_KEY = '[secret access key]'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.%s.amazonaws.com' % (AWS_STORAGE_BUCKET_NAME, AWS_REGION)
# Static Setting
STATIC_URL = "http://%s/static/" % AWS_S3_CUSTOM_DOMAIN
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
# Media Setting
MEDIA_URL = "http://%s/media/" % AWS_S3_CUSTOM_DOMAIN
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
# 정적파일을 수집하는 명령어 실행
python3 manage.py collectstatic
# S3에서 연동 확인


'project' 카테고리의 다른 글
S3에 CloudFront 배포 (0) | 2023.12.08 |
---|---|
면접 참고 자료 (0) | 2023.12.06 |
CSRF 검증 (0) | 2023.12.06 |
Elasticache Redis (1) | 2023.12.06 |
오토 스케일링 (2) | 2023.12.05 |