簡體   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