Getting an item from the DynamoDB table using the AWS SDK for .Net
Let's understand how to get an item from the DynamoDB table using the AWS SDK for .Net.
Getting ready
To perform this operation, you can use the IDE of your choice.
How to do it…
Let's try to understand how to retrieve a stored item from the DynamoDB table using .Net:
Create an instance of the
DynamoDB
client:AmazonDynamoDBClient client = new AmazonDynamoDBClient(); string tableName = "productTable";
Create a
GetItemRequest
that specifies theprimary
key details:var request = new GetItemRequest { TableName = tableName, Key = new Dictionary<string,AttributeValue>() { {"id",new AttributeValue{ N="20"} }, {"type", new AttributeValue{ S="phone"} } }, };
Here, we have a composite primary key as the ID and type.
Invoke the
GetItem
method with a specified request, and fetch the items from the results:var response = client.GetItem(request); var result = response.GetItemResult;
How it works…
The API invocations...