本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
重要
This section refers to API version 2011-12-05,
which is deprecated and should not be used for new
applications.
如需目前低階 的文件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 佈建容量模式。 類型:數字 |
特殊錯誤
沒有此操作特定的錯誤。
範例
如需使用 的範例 AWS 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
}