boto - 钥匙到底是什么?

boto - What exactly is a key?

正如标题所说,boto中的key是什么?

我无法在他们的官方文档或任何其他第三方网站上找到此信息。有人可以提供此信息吗?

以下是 key object 的一些用法示例:

def download_file(key_name, storage):
    key = bucket.get_key(key_name)
    try:
        storage.append(key.get_contents_as_string())
    except:
        print "Some error message."

和:

for key in keys_to_process:
    pool.spawn_n(download_file, key.key, file_contents)
pool.waitall()

由于您似乎在谈论简单存储服务 (S3),因此您会在 S3 文档的第 1 页找到该信息。

Each object is stored and retrieved using a unique developer-assigned key.

A key is the unique identifier for an object within a bucket. Every object in a bucket has exactly one key. Because the combination of a bucket, key, and version ID uniquely identify each object, Amazon S3 can be thought of as a basic data map between "bucket + key + version" and the object itself. Every object in Amazon S3 can be uniquely addressed through the combination of the web service endpoint, bucket name, key, and optionally, a version. For example, in the URL http://doc.s3.amazonaws.com/2006-03-01/AmazonS3.wsdl, "doc" is the name of the bucket and "2006-03-01/AmazonS3.wsdl" is the key.

http://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction.html

密钥只是一个字符串 -- 存储桶中对象的“路径和文件名”,没有前导 /

在您的代码示例中 - 键是对存储桶中唯一标识符的对象引用。

将存储桶视为数据库中的 table 将键视为 table 中的行 您引用存储桶中的密钥(更广为人知的对象)。

通常在 boto(不是 boto3)中这样工作

from boto.s3.connection import S3Connection
connection = S3Connection()  # assumes you have a .boto or boto.cfg setup
bucket = connection.get_bucket('my_bucket_name_here') # this is like the table name in SQL, select OBJECT form TABLENAME
key = bucket.get_key('my_key_name_here') this is the OBJECT in the above SQL example.  key names are a string, and there is a convention that says if you put a '/' in the name, a viewer/tool should treat it like a path/folder for the user, e.g.  my/object_name/is_this is really just a key inside the bucket, but most viewers will show a my folder, and an object_name folder, and then what looks like a file called is_this simply by UI convention