Skip to content

Instantly share code, notes, and snippets.

@martyzz1
Created December 21, 2015 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martyzz1/71c8c487a067e1eec31d to your computer and use it in GitHub Desktop.
Save martyzz1/71c8c487a067e1eec31d to your computer and use it in GitHub Desktop.
How to connect to None US S3 using Boto2, for CNAME'd subdomain buckets - useful if you get S3ResponseError: S3ResponseError: 301 Moved Permanently or CertificateError: hostname 'sub.primarydomain.com.s3.amazonaws.com' doesn't match either of '*.s3.amazonaws.com', 's3.amazonaws.com
conn = boto.s3.connect_to_region(
'eu-west-1',
aws_access_key_id=<AWS_ACCESS_KEY_ID>,
aws_secret_access_key=<AWS_SECRET_ACCESS_KEY>,
calling_format=ProtocolIndependentOrdinaryCallingFormat()
)
bucket = conn.get_bucket('sub.primarydomain.com')
prefix = 'some/prefix/'
rs = bucket.list(prefix=prefix)
for key in rs:
print key.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment