繁体   English   中英

如何在Python(Boto lib)中像在Openstack Swift中那样获取Amazon S3存储桶的元数据/标头?

[英]How to get metadata/headers of an Amazon S3 Bucket in Python (Boto lib) like in Openstack Swift?

我想获取Amazon S3存储桶的元数据/标头列表吗?

我可以在OpenStack Swift Storage中获取元数据,如下所示-> curl命令,请求元数据:

curl -i http://localhost:8080/v1/AUTH_test/container1 -X HEAD -H "X-Auth-Token: AUTH_tk6194fghrt"

以上curl命令的响应:

HTTP/1.1 204 No Content
Content-Length: 0
X-Container-Object-Count: 6
Accept-Ranges: bytes
X-Trans-Id: tx0ff9f8541e2c4e019dea1-0053eb48a7
Date: Wed, 13 Aug 2014 11:14:47 GMT
X-Container-Meta-Century: Nineteenthsssssssssssss
X-Timestamp: 1399987571.97634
X-Container-Meta-Author: Mustafa
X-Container-Bytes-Used: 3978833
Content-Type: text/plain; charset=utf-8
X-Trans-Id: tx1c2734f1e4ca4f3e835da-0053eb497d

在openstack swift中,我可以使用python-swiftclient API获取上述swift容器(存储桶)的元数据。
我想对AmazonS3存储桶执行相同的操作。 因此,如何使用Python获取AmazonS3存储桶元数据 ?(我使用的是boto库)
有可能还是我在“狂奔”?

更新:
我正在尝试获取存储桶的元数据,而不是存储桶的键。

您可以尝试以下boto代码段:

from boto.s3.connection import S3Connection
conn = S3Connection('<aws access key>', '<aws secret key>')
mybucket = conn.get_bucket('mybucket')
for key in mybucket:
    key = mybucket.get_key(key.name)
    print key.name
    print key.get_metadata('revision')

您可以在以下网址阅读有关boto的更多信息: https : //boto.readthedocs.org/en/latest/s3_tut.html

希望能有所帮助。

更新:

您可以尝试的其他方法:

resp = conn.make_request("HEAD", mybucket)
print resp.getheaders()

希望您在响应头中看到一些想要的元数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM