Issues

Issue #123 new

Add CUSTOM_HOST to s3 connection

devs
created an issue

When using S3 from other datacenter like sa-east-1 the host to do the connection need to be changed. Currently there is no way to set it.

I'm attaching a simple patch to add a CUSTOM_HOST setting.

Comments (4)

  1. k4ml

    I have been hit by this issue too today. Been using django-storages since last year and never had any issue until today. Related issue on boto repo:-

    https://github.com/boto/boto/issues/621

    There are 2 pull requests on this:-

    http://code.larlet.fr/django-storages/pull-request/66/s3boto-backend-allows-custom-s3-host-port/diff

    http://code.larlet.fr/django-storages/pull-request/52/custom-host-setting

    As a workaround you can define your own STATICFILES_STORAGE class and override the connection method like below:-

    from storages.backends.s3boto import S3Connection, setting
    from storages.backends.s3boto import S3BotoStorage as S3BotoStorageOrig
    
    class S3BotoStorage(S3BotoStorageOrig):
        custom_host = setting('AWS_S3_CUSTOM_HOST', S3Connection.DefaultHost)
    
        @property
        def connection(self):
            if self._connection is None:
                self._connection = self.connection_class(
                    self.access_key, self.secret_key,
                    host=self.custom_host,
                    calling_format=self.calling_format)
            return self._connection
    

    Then change your settings.py to use this class instead:-

    STATICFILES_STORAGE = 'myapp.storage.S3BotoStorage'

  2. Log in to comment