12

i would like to use django-storages with minio so i tryd to adopt settings, configs etc. I found on the web but for some reason my access key or the way it gets provided fails with the following error:

botocore.exceptions.ClientError: An error occurred (InvalidAccessKeyId) when calling the PutObject operation: The AWS Access Key Id you provided does not exist in our records.

if i run manage.py collectstatic

settings.py

#S3 config
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'MyProject/static'),
]
AWS_ACCESS_KEY_ID = '9VOWWCTSMX4ZEGVW7N9D'
AWS_SECRET_ACCESS_KEY = 'zJFf9BYWk0TM3FVwyY98UFy0o+DQF0oY1vCXgLqV'
AWS_STORAGE_BUCKET_NAME = 'static'
AWS_S3_CUSTOM_DOMAIN = '127.0.0.1:9000'

AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}

AWS_LOCATION = 'static'
STATIC_URL = 'http://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

Is there maybe someone that has already done this?

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

13

Here is what I did to get it to work

# settings.py

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

AWS_STORAGE_BUCKET_NAME = 'static'

AWS_ACCESS_KEY_ID = minio_access_key
AWS_SECRET_ACCESS_KEY = minio_secret_key
AWS_S3_ENDPOINT_URL = minio_address (eg. http://localhost:9000)

Versions:

  • boto3==1.10.45
  • Django==3.0.1
  • django-storages==1.8
  • Minio==2019-12-26T01:55:09Z (Docker image built from the source code to run on RPi4)

Note: versions were latest when installed using pip install <package>

I didn't attempt to use django-minio-storage since it does not support Django3.

If you have upgraded your package versions, try what I did. If not try setting S3_HOST = '127.0.0.1:9000' .

AWS_S3_ENDPOINT_URL from django-storage docs

AWS_S3_ENDPOINT_URL (optional: default is None, boto3 only)
Custom S3 URL to use when connecting to S3, including scheme. Overrides AWS_S3_REGION_NAME and AWS_S3_USE_SSL . To avoid AuthorizationQueryParametersError error, AWS_S3_REGION_NAME should also be set.

Troubleshooting
Disconnect from the internet and run manage.py collectstatic to see the address to which boto fails to connect.

Yuri L
  • 411
  • 5
  • 8