Amazon DynamoDB
Developer Guide (API Version 2012-08-10)

Step 5: Read and Display a Record from the Movies 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 Ddb_Intro { /*-------------------------------------------------------------------------- * ReadingMovie_async *--------------------------------------------------------------------------*/ public static async Task<bool> ReadingMovie_async( int year, string title, bool report ) { // 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); operationSucceeded = false; operationFailed = false; try { Task<Document> readMovie = moviesTable.GetItemAsync(hash, range, token); if( report ) Console.WriteLine( " -- Reading the {0} movie \"{1}\" from the Movies table...", year, title ); movie_record = await readMovie; if( movie_record == null ) { if( report ) Console.WriteLine( " -- Sorry, that movie isn't in the Movies table." ); return ( false ); } else { if( report ) Console.WriteLine( " -- Found it! The movie record looks like this:\n" + movie_record.ToJsonPretty( ) ); operationSucceeded = true; return ( true ); } } catch( Exception ex ) { Console.WriteLine( " FAILED to get the movie, because: {0}.", ex.Message ); operationFailed = true; } return ( false ); } } }

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

On this page: