I have configured the django-storages to point to OCI bucket. Below is the configuration:
AWS_S3_ACCESS_KEY_ID = env('AWS_BUCKET_KEY')
AWS_SECRET_ACCESS_KEY = env('AWS_BUCKET_SECRET')
AWS_BUCKET_NAMESPACE = env('AWS_BUCKET_NAMESPACE')
AWS_STORAGE_BUCKET_NAME = env('AWS_BUCKET_NAME')
AWS_S3_BUCKET_REGION = env('AWS_S3_BUCKET_REGION')
AWS_S3_ENDPOINT_URL = f'https://{AWS_BUCKET_NAMESPACE}.compat.objectstorage. {AWS_S3_BUCKET_REGION}.oraclecloud.com'
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
AWS_LOCATION = f'{AWS_S3_ENDPOINT_URL}/{AWS_STORAGE_BUCKET_NAME}'
AWS_DEFAULT_ACL = 'public-read'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
# Use AWS_S3_ENDPOINT_URL here if you haven't enabled the CDN and got a custom domain.
STATIC_URL = '{}/{}/'.format(AWS_LOCATION, 'static')
STATIC_ROOT = 'var/static/'
STATICFILES_DIRS = [
BASE_DIR / "static"
]
MEDIA_URL = '{}/{}/'.format(AWS_LOCATION, 'media')
MEDIA_ROOT = 'media/'
and this is the custom storage config
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
location = 'static'
class MediaStorage(S3Boto3Storage):
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
location = 'media'
All my static files are being served and no issues, but the application doesn't recognize the style files at all.
Also when I try to upload a new file, it gives the following error:
botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the PutObject operation:
The secret key required to complete authentication could not be found. The region must be specified if this is not the home region for the tenancy.
What could be the issue?
------ UPDATE ------
for this issue:
Also when I try to upload a new file, it gives the following error:
botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the PutObject operation: The secret key required to complete authentication could not be found. The region must be specified if this is not the home region for the tenancy.
It was resolved by adding the keys in the custom storage class:
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
access_key = settings.AWS_S3_ACCESS_KEY_ID
secret_key = settings.AWS_SECRET_ACCESS_KEY
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
region_name = settings.AWS_S3_BUCKET_REGION
location = 'static'
class MediaStorage(S3Boto3Storage):
access_key = settings.AWS_S3_ACCESS_KEY_ID
secret_key = settings.AWS_SECRET_ACCESS_KEY
bucket_name = settings.AWS_STORAGE_BUCKET_NAME
region_name = settings.AWS_S3_BUCKET_REGION
location = 'media'
The issue of style not reflecting persists.
The error message you're seeing, botocore.exceptions.ClientError: An error occurred (SignatureDoesNotMatch) when calling the PutObject operation, typically indicates that there's a problem with your AWS credentials (access key ID and secret access key).
Here are a few things you can check:
Check your credentials: Make sure that the AWS_S3_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY values are correct. These should be the access key ID and secret access key for an IAM user in your AWS account that has the necessary permissions to access the S3 bucket.
Check your bucket name: Make sure that the AWS_STORAGE_BUCKET_NAME value is correct and that the bucket exists in your AWS account.
Check your region: The error message also mentions that the region must be specified. Make sure that the AWS_S3_BUCKET_REGION value is correct and matches the region where your S3 bucket is located.
Check your endpoint URL: The AWS_S3_ENDPOINT_URL should be correct and reachable. It seems you're using Oracle Cloud Infrastructure (OCI) Object Storage service, make sure the endpoint URL is correct as per OCI documentation.
If you've checked all of these and you're still seeing the error, it might be a good idea to try using the boto3 library directly (outside of Django and django-storages) to connect to your S3 bucket and perform a simple operation, like listing the objects in the bucket. This can help you determine whether the issue is with your AWS credentials or with the way django-storages is using them.