我正在尝试访问http://s3.amazonaws.com/commoncrawl/parse-output/segment/ http://s3.amazonaws.com/commoncrawl/parse-output/segment/桶与 boto。我不知道如何将其翻译为 boto.s3.bucket.Bucket() 的名称。
这就是我想要的要点:
s3 = boto.connect_s3()
cc = boto.s3.bucket.Bucket(connection=s3, name='commoncrawl/parse-output/segment')
requester = {'x-amz-request-payer':'requester'}
contents = cc.list(headers=requester)
for i,item in enumerate(contents):
print item.__repr__()
我收到“boto.exception.S3ResponseError:S3ResponseError:400 Bad Request ...指定的存储桶无效...”
The AWS 文档列出了 S3 的四种可能的 url 格式 http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html-- 这是我刚刚拼凑起来的内容,用于提取所有不同 url 格式的存储桶和区域。
import re
def bucket_name_from_url(url):
""" Gets bucket name and region from url, matching any of the different formats for S3 urls
* http://bucket.s3.amazonaws.com
* http://bucket.s3-aws-region.amazonaws.com
* http://s3.amazonaws.com/bucket
* http://s3-aws-region.amazonaws.com/bucket
returns bucket name, region
"""
match = re.search('^https?://(.+).s3.amazonaws.com/', url)
if match:
return match.group(1), None
match = re.search('^https?://(.+).s3-([^.]+).amazonaws.com/', url)
if match:
return match.group(1), match.group(2)
match = re.search('^https?://s3.amazonaws.com/([^\/]+)', url)
if match:
return match.group(1), None
match = re.search('^https?://s3-([^.]+).amazonaws.com/([^\/]+)', url)
if match:
return match.group(2), match.group(1)
return None, None
像这样的事情真的应该进入 boto ......亚马逊,我希望你在听
编辑 2018 年 10 月 10 日:
存储桶正则表达式现在应该捕获带句点的存储桶名称。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)