GetItem
重要
本节介绍已经弃用的 API 版本 2011-12-05,不应用于新应用程序。
有关当前低级别 API 的文档,请参阅 Amazon DynamoDB API 参考。
描述
GetItem
操作为匹配主键的项目返回一组 Attributes
。如果没有匹配项目,则 GetItem
不返回任何数据。
GetItem
操作默认提供最终一致性读取。如果您的应用程序不接受最终一致性读取,请使用 ConsistentRead
。尽管此操作可能比标准读取所需的时间长,但它始终返回上次更新的值。有关更多信息,请参阅 DynamoDB 读取一致性。
请求
语法
// This header is abbreviated. // For a sample of a complete header, see DynamoDB 低级 API. POST / HTTP/1.1 x-amz-target: DynamoDB_20111205.GetItem content-type: application/x-amz-json-1.0 {"TableName":"Table1", "Key": {"HashKeyElement": {"S":"AttributeValue1"}, "RangeKeyElement": {"N":"AttributeValue2"} }, "AttributesToGet":["AttributeName3","AttributeName4"], "ConsistentRead":Boolean }
名称 | 描述 | 必填 |
---|---|---|
TableName
|
包含请求项目的表的名称。 类型:字符串 |
是 |
Key
|
定义项目的主键值。有关主键的更多信息,请参阅 主键。 类型: |
是 |
AttributesToGet
|
属性名称的数组。如果未指定属性名称,则返回所有属性。如果找不到某些属性,则不会出现在结果中。 类型:数组 |
否 |
ConsistentRead
|
如果设置为 类型:布尔值 |
否 |
响应
语法
HTTP/1.1 200 x-amzn-RequestId: 8966d095-71e9-11e0-a498-71d736f27375 content-type: application/x-amz-json-1.0 content-length: 144 {"Item":{ "AttributeName3":{"S":"AttributeValue3"}, "AttributeName4":{"N":"AttributeValue4"}, "AttributeName5":{"B":"dmFsdWU="} }, "ConsumedCapacityUnits": 0.5 }
名称 | 描述 |
---|---|
Item
|
包含请求的属性。 类型:属性名称-值对映射。 |
ConsumedCapacityUnits |
操作消耗的读取容量单位数。此值显示应用于预置吞吐量的数字。如果请求的项目不存在,将根据读取类型,消耗最小读取容量单位。有关更多信息,请参阅DynamoDB 预置容量模式。 类型:数字 |
特殊错误
没有特定于此操作的错误。
示例
有关使用 Amazon SDK 的示例,请参阅 使用 DynamoDB 中的项目和属性。
示例请求
// This header is abbreviated. // For a sample of a complete header, see DynamoDB 低级 API. POST / HTTP/1.1 x-amz-target: DynamoDB_20111205.GetItem content-type: application/x-amz-json-1.0 {"TableName":"comptable", "Key": {"HashKeyElement":{"S":"Julie"}, "RangeKeyElement":{"N":"1307654345"}}, "AttributesToGet":["status","friends"], "ConsistentRead":true }
示例响应
请注意,ConsumedCapacityUnits 值为 1,因为可选参数 ConsistentRead
设置为 true
。如果同一请求的 ConsistentRead
设置为 false
(或未指定),则响应最终一致,ConsumedCapacityUnits 值为 0.5。
HTTP/1.1 200 x-amzn-RequestId: 8966d095-71e9-11e0-a498-71d736f27375 content-type: application/x-amz-json-1.0 content-length: 72 {"Item": {"friends":{"SS":["Lynda, Aaron"]}, "status":{"S":"online"} }, "ConsumedCapacityUnits": 1 }