0

我发现 boto3 的官方文档(https://boto3.readthedocs.org/en/latest/reference/services/s3.html#S3.Bucket.create)与实际返回的内容之间存在令人沮丧的不匹配.

只是为了确保,我使用的是 boto3 1.2.1 和 botocore 1.3.2(都安装了 pip)。

我专门谈论使用以下boto3.Session方法创建存储桶:

import boto3
session = boto3.Session(region_name = 'us-west-2', \
                    aws_access_key_id = 'AAA', \
                    aws_secret_access_key = 'BBB')
s3 = session.resource('s3')
bucket = s3.Bucket('testbucket').create()

我在文档中被告知该s3.Bucket('testbucket').create()命令返回的字典看起来像

{
    'Location': 'string'
}

但相反,我得到了一个看起来像这样的字典:

{
    u'Location': '/testbucket',
    'ResponseMetadata': {
        'HTTPStatusCode': 200,
        'HostId': 'alphnumericalmixed/alphanumericalmixed',
        'RequestId': 'MIXEDUPPERANDNUMBERS123'
    }
}

如果我尝试通过调用它的delete()方法来删除一个 S3 对象,我也会得到类似的东西,例如:

# some initialisation as above code
obj=bucket.put_object(Body='123', Key='456')
print obj.delete()

我在哪里得到:

{'ResponseMetadata': 
{'HTTPStatusCode': 204, 
'HostId': 'something/something', 
'RequestId': 'SOMETHING'}}

而不是(https://boto3.readthedocs.org/en/latest/reference/services/s3.html#S3.Object.delete):

{
'DeleteMarker': True|False,
'VersionId': 'string',
'RequestCharged': 'requester'
}

我知道 boto3 是 botocore 库的一个相关包装器,而RequestID我要返回的字典中的键最终来自botocore/parsers.py. 我理解createreturn 因为它实际上有额外的信息,但我不明白的是put_object()方法 return不包含任何类似于文档的内容

我正在努力解决的是官方文档是否对我撒谎。

4

1 回答 1

0

正如乔丹菲利普斯所说:

“文档没有说谎,当没有任何东西可以返回时,他们不会返回任何东西。没有版本控制,所以没有版本 ID 或删除标记。没有随请求发送的 'RequestCharged',所以那里也没有任何东西。”

我想这是我没想到的一件事。我假设返回字典只包含记录的值,而不是其他值。

于 2015-11-02T21:03:40.747 回答