Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to S3 buckets with periods in their name, when using Boto on Heroku

We're getting a certificate error when trying to connect to our S3 bucket using Boto. Strangely, this only manifests itself when accessing a bucket with periods in its name WHILE running on Heroku.

from boto.s3.connection import S3Connection
conn = S3Connection({our_s3_key}, {our_s3_secret})
bucket = conn.get_bucket('ourcompany.images')

Raises the following error:

CertificateError: hostname 'ourcompany.images.s3.amazonaws.com' doesn't match either of '*.s3.amazonaws.com', 's3.amazonaws.com'

But the same code works fine when run locally, and would also work on Heroku if the bucket name were 'ourcompany-images' instead of 'ourcompany.images'

like image 505
Yarin Avatar asked Dec 26 '14 02:12

Yarin


1 Answers

According to the relevant github issue, add this to the configuration:

[s3]
calling_format = boto.s3.connection.OrdinaryCallingFormat

Or, specify the calling_format while instantiating an S3Connection:

from boto.s3.connection import OrdinaryCallingFormat

conn = S3Connection(access_key, secret_key, calling_format=OrdinaryCallingFormat())

The code worked for you locally and didn't work on heroku, most likely, because of the different python versions used. I suspect you are using 2.7.9 runtime on heroku, which has enabled certificate checks for stdlib http clients.

like image 112
alecxe Avatar answered Sep 20 '22 07:09

alecxe