0

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.

2
  • 2
    Try adding os.environ.setdefault('S3_USE_SIGV4', 'True') to your env.py.
    – Alasdair
    Aug 21, 2019 at 12:56
  • Perfect. That's done the trick. Thanks very much!
    – samalty
    Aug 21, 2019 at 13:09

1 Answer 1

4

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')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.