Troubles using Amazon S3 with Europe based buckets in django-storages

爷,独闯天下 提交于 2021-01-28 07:34:50

问题


Question is regarding Amazon S3 buckets in EU.

I have a Django project hosted locally and decided to store media files in Amazon S3 buckets. For doing this I use Django-storages app with the following settings in settings.py:

AWS_ACCESS_KEY_ID = "xxxxxxx"
AWS_SECRET_ACCESS_KEY = "xxxxxxxxxx"
AWS_STORAGE_BUCKET_NAME = 'hadcasetest'

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

MEDIA_URL = 'http://' + AWS_STORAGE_BUCKET_NAME + '.s3.amazonaws.com/'


THUMBNAIL_DEFAULT_STORAGE = DEFAULT_FILE_STORAGE
THUMBNAIL_BASEDIR = "thumbnails"
THUMBNAIL_MEDIA_URL = MEDIA_URL

Well, it works when I use bucket from USA region and doesn't when I use buckets from Europe. I tried all possible locations in Europe – they all do not work.

Type of error I get: S3ResponseError: 400 Bad Request

Question is what should I change to get access via Django -storages to Europe based buckets to use them in Django app?

P.S. I can use AWS CLI to write in each buckets even in European ones but, Django-storages can not.

Should I obtain specific EU credentials perhaps?


回答1:


I added these parameters in settings.py and it helped:

AWS_S3_HOST = "s3.eu-central-1.amazonaws.com"
S3_USE_SIGV4 = True
AWS_S3_REGION_NAME = "eu-central-1"


来源:https://stackoverflow.com/questions/56513416/troubles-using-amazon-s3-with-europe-based-buckets-in-django-storages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!