SignatureDoesNotMatch when calling PutObject with Django, Django-Storage, AWS S3, boto3

I created a Django App and host it on Heroku where I specified all setting vars such as Access Key ID (see Settings file).

AWS_ACCESS_KEY_ID= config("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY_ID= config("AWS_SECRET_ACCESS_KEY_ID")
AWS_STORAGE_BUCKET_NAME= config("AWS_STORAGE_BUCKET_NAME")
AWS_S3_CUSTOM_DOMAIN=f"{AWS_STORAGE_BUCKET_NAME}.s3.us-west-1.amazonaws.com"   
AWS_DEFAULT_ACL="public-read" 
AWS_S3_OBJECT_PARAMETERS = {"CacheControl": "max-age=86400" }
    
AWS_LOCATION= "static"  
AWS_S3_REGION_NAME = "EU-west-1" AWS_QUERYSTRING_AUTH=False
AWS_HEADERS={"Access-Control-Allow-Origin":"*", }
DEFAULT_FILE_STORAGE= "storages.backends.s3boto3.S3Boto3Storage"
STATICFILES_STORAGE= "storages.backends.s3boto3.S3StaticStorage"
STATIC_URL= f"HTTPS://{AWS_S3_CUSTOM_DOMAIN}/static/" 
MEDIA_URL=f"HTTPS://{AWS_S3_CUSTOM_DOMAIN}/media/"
DEBUG_PROPAGATE_EXCEPTIONS = True
ASSETS_ROOT = os.getenv('ASSETS_ROOT',"https://{AWS_S3_CUSTOM_DOMAIN}/static/assets") 
     
LOGGING={
         "version":1, 
         "disable_existing_loggers": False,
         "formatters":{
             "verbose":{
                 "format":"[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
                 "datefmt":"%d/%b/%Y %H:%M:%S"
             },
             "simple":{
                 "format": " %(levelname)s  %(message)s",
             }
         },
         "handlers":{
             "console":{
                 "level": "DEBUG",
                 "class": "logging.StreamHandler",
             },
         },
         "loggers":{
            "myapp":{
                 "handlers": ["console"],
                "level": "DEBUG"
             }
       } }

Relevant requirements:

django-storages==1.12.3    
boto3==1.26.31  

Anyone any ideas on how to solve this?

I tried the IAM user with full access, only S3 Full access, the Access Keys of the global account and I just keep geeting the error: "botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when cagettinghe the PutObject operation: The request signature we calculated does not match the signature you provided. Check your key and signing method." when trying to upload something to S3. The website then outputs:

Internal Server Error

The server encountered an unexpected internal server error

(generated by the waitress)

The logger I added to the settings file on Django is not helpful at all as it just shows me a SignatureDoesNotMatch error.

I tried Access Keys with + and without as this might be the source of the error. I couldn't find any best practices on how to insert the keys to the Heroku settings but a lot of ppl reporting errors when copying the keys from the AWS website. I checked it with the CSV file and the website output.

I tried to add the images through the admin page in case my HTML page is faulty. Same error. The

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1277.0.min.js"></script>

the line is added to the HTML page as well. And I save it through

form.save()

on my HTML page.

Back to Top