Retrieves a set of Attributes for an item that matches the primary key.
The GetItem operation provides an eventually-consistent read by default. If eventually-consistent reads are not acceptable for your application, use ConsistentRead . Although this operation might take longer than a standard read, it always returns the last updated value.
Declaration Syntax
C# |
public GetItemResponse GetItem( GetItemRequest getItemRequest )
Parameters
- getItemRequest (GetItemRequest)
- Container for the necessary parameters to execute the GetItem service method on AmazonDynamoDB.
Return Value
The response from the GetItem service method, as returned by AmazonDynamoDB.
Examples
This example shows how to get an item in a table.
CopyGetItem sample
// Create a client AmazonDynamoDBClient client = new AmazonDynamoDBClient(); // Define item key // Hash-key of the target item is string value "Mark Twain" // Range-key of the target item is string value "The Adventures of Tom Sawyer" Key key = new Key { HashKeyElement = new AttributeValue { S = "Mark Twain" }, RangeKeyElement = new AttributeValue { S = "The Adventures of Tom Sawyer" } }; // Create GetItem request GetItemRequest request = new GetItemRequest { TableName = "SampleTable", Key = key, }; // Issue request GetItemResult result = client.GetItem(request).GetItemResult; // View response Console.WriteLine("Item:"); Dictionary<string, AttributeValue> item = result.Item; foreach (var keyValuePair in item) { Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]", keyValuePair.Key, keyValuePair.Value.S, keyValuePair.Value.N, string.Join(", ", keyValuePair.Value.SS.ToArray()), string.Join(", ", keyValuePair.Value.SS.ToArray())); }
Exceptions