AWS News Blog

Amazon DynamoDB and the AWS SDK for .NET

Pavel Safronov, a developer on our SDK and Tools team, sent the following guest post my way!

— Jeff;


The AWS SDK for .NET provides a simple client for our new service, Amazon DynamoDB. This client gives you a straight-forward way to interface with this Internet-scale NoSQL database service. But what you might not know is that the SDK also provides an object persistence framework for Amazon DynamoDB.

The object persistence framework enables you to define and use .NET classes like the one shown below to represent and manage data in Amazon DynamoDB. The frameworkspecifically the DynamoDBContext objecttakes care of all the nitty-gritty details of marshalling and unmarshalling your data from .NET objects to Amazon DynamoDB attributes. All you need to do is define the classes and treat them like any other .NET data types.

[DynamoDBTable ( “Movies” ) ]
public class Movie
{
    [DynamoDBHashKey ]
    public string Title { get ; set ; }
    [DynamoDBRangeKey (AttributeName = “Released” ) ]
    public DateTime ReleaseDate { get ; set ; }

    public List<string> Genres { get; set; }

    [DynamoDBProperty(“Actors”)]
    public List<string> ActorNames { get; set; }

    [DynamoDBIgnore]
    public string Comment { get; set; }
}

As you can see, the class has a few attributes marking it up. These attributes specify the table to store the data in, the keys for the table, and which properties should either not be stored or be stored using a different name than in the class. These attributes are all you need to add to your code to seamlessly interact with Amazon DynamoDB.

The sample below shows basic CRUD (Create, Read, Update, Delete) operations that can be performed on these objects. Using the object persistence framework is as simple as making a Save or a Load call!

Actor actor = new Actor ( “John Doe” ) ;
context . Save (actor ) ;

actor = context.Load<Actor>(“John Doe”);
actor.Email = “john.doe@example.net”;
context.Save(actor);

context.Delete(actor);

This article provides an in-depth walkthrough of using the object persistence framework to design a sample movie-tracking application. The article discusses the data structure aspects of the application, provides a sample schema, and shows the various interactions with Amazon DynamoDB.

Pavel Safronov
Software Development Engineer

PS: We are hiring software development engineers and product managers. If you are passionate about enabling developers to use AWS, get in touch with us at aws-devresources-jobs@amazon.com.

 

Jeff Barr

Jeff Barr

Jeff Barr is Chief Evangelist for AWS. He started this blog in 2004 and has been writing posts just about non-stop ever since.