Search code examples
pythondjangoamazon-s3customization

Django S3 using Boto3 with OpenTelekomCloud (OTC)


I followed this tutorial https://simpleisbetterthancomplex.com/tutorial/2017/08/01/how-to-setup-amazon-s3-in-a-django-project.html to setup an S3 integration of my Django application with S3. I tested with AWS and it works fine, but for production uses I want to use a different S3 provider: OpenTelekomCloud aka OTC.

Using the following client-code I can access both OTC and AWS, depending on the endpoint_url:

session = boto3.session.Session()
s3_client = session.client(
            service_name='s3',
            aws_access_key_id='XXXXXXXXXXX',
            aws_secret_access_key='XXXXXXXXXXXXXXXXXXXXXXXXX',
            endpoint_url='https://obs.eu-de.otc.t-systems.com',
            # region_name='eu-de',
            use_ssl=True,
            verify=True,
        )

print(s3_client.list_buckets())

But I can't move the config to the settings.py file of my Django app the right way for OTC, while it works fine with AWS.

AWS_ACCESS_KEY_ID = 'XXXXXXXXXXXXX'
AWS_SECRET_ACCESS_KEY = 'XXXXXXXXXXXXXXXXXX'
AWS_STORAGE_BUCKET_NAME = 'my-bucket'
AWS_S3_CUSTOM_DOMAIN = 'obs.eu-de.otc.t-systems.com'  

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

Tried several different configs but am always getting the following response.

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

What would be the right way to config my settings.py for OTC to make it work?


Solution

  • Replaced this

    AWS_S3_CUSTOM_DOMAIN = 'obs.eu-de.otc.t-systems.com'

    by this

    AWS_S3_ENDPOINT_URL = 'http://obs.eu-de.otc.t-systems.com'

    and it worked!