samalty
samalty

Reputation: 141

Amazon Web Services - S3 'The authorization mechanism you have provided is not supported' in Django

I am trying to configure my Django application to host image files within an AWS S3 bucket, but the images won't load. Instead, I receive the following error message: 'The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256'

I'm aware that this issue has been raised by others using different languages, and I've tried some suggested solutions but nothing has worked so far. My config settings are displayed below:

# env.py

os.environ.setdefault("AWS_ACCESS_KEY_ID", "**********")
os.environ.setdefault("AWS_SECRET_ACCESS_KEY", "AWS_ACCESS_KEY_ID", "**********")
os.environ.setdefault("AWS_STORAGE_BUCKET_NAME", "mybucket")
os.environ.setdefault("AWS_S3_REGION_NAME", "eu-west-2")

# settings.py

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_S3_REGION_NAME = os.environ.get('AWS_S3_REGION_NAME')

AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

# boto.cfg

[s3] use-sigv4 = True

I initially didn't include AWS_S3_REGION_NAME in my configuration because in the S3 console it says 'S3 does not require region selection'. What I read regarding the error message suggested that this was necessary, but adding it to the config hasn't helped. I also added the 'boto.cfg' file, following AWS guidance (https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html) but this hasn't helped either.

Upvotes: 0

Views: 5169

Answers (1)

Alasdair
Alasdair

Reputation: 309099

I'm not sure why setting use-sigv4 = True in the config file did not work for you. You can set an environment variable instead:

# env.py

os.environ.setdefault('S3_USE_SIGV4', 'True')

Upvotes: 4

Related Questions