Step 5: Read and Display a Record from the DynamoDB Table - Amazon DynamoDB

Step 5: Read and Display a Record from the DynamoDB Table

In this step of the Microsoft .NET and DynamoDB Tutorial, you retrieve and display the new movie record that you added in Step 4. The Main function in DynamoDB_intro does this by waiting on ReadingMovie_async, which is implemented in the 05_ReadingItem.cs file.

using System; using System.Threading.Tasks; using Amazon.DynamoDBv2.DocumentModel; namespace DynamoDB_intro { public static partial class DdbIntro { public static async Task<Document> ReadingMovie_async(int year, string title) { // Create Primitives for the HASH and RANGE portions of the primary key Primitive hash = new Primitive(year.ToString(), true); Primitive range = new Primitive(title, false); try { var movieItem = await MoviesTable.GetItemAsync(hash, range, Token); return movieItem; } catch (Exception) { return null; } } } }

ReadingMovie_async in turn waits on the DynamoDB Table.GetItemAsyn method to retrieve the new movie record as a Document. ReadingMovie_async then displays the movie as JSON text using the Document.ToJsonPretty method.

For More Information

Next Step

Step 6: Update the New Movie Record in the DynamoDB Table