Cloud computing offerings such as Microsoft Azure and Amazon SimpleDB allow developers to focus on coding without having to worry about the infrastructure. This week we look at Amazon’s new cloud service called DynamoDB.

NoSQL in the cloud

While relational databases do many things well, there are instances where its rigid nature is overkill or it just doesn’t perform great. Amazon recognized this with its shopping cart and site problems years ago, and its DynamoDB NoSQL system evolved from the company’s work to resolve those issues. An interesting facet of the DynamoDB service is its extensive use of solid state drives to help performance.

You might be wondering how DynamoDB differs from other Amazon products, most notably SimpleDB. The official Amazon documentation states DynamoDB overcomes some of the scaling limitations of SimpleDB. It also notes that the query flexibility offered by SimpleDB is better for smaller workloads.

Up and running

Getting started with Amazon Web Services (AWS) is a straightforward process; you go to the AWS site and click the Sign Up Now link. Amazon offers a pay-as-you-go model, so you only have to pay for what is used. AWS’s Free Usage Tier allows you to get your feet wet with DynamoDB at no charge; this includes 100 MB of storage along with 5 data writes/second and 10 data reads/second — so it’s not a lot of traffic, but it’s not designed for a production system since they need to make money.

Once you sign up, the AWS console provides an easy-to-use interface (Figure A). From this interface, you choose DynamoDB and start using the service. The basic DynamoDB concept includes tables, items, and attributes. A database is a collection of tables; a table is a collection of items; and each item is a collection of attributes. Each attribute is a name-value pair, which is either single- or multi-valued. Each table has a primary key, which is either Hash Type (one value) or a Hash and Range Type (two values). DynamoDB supports number and string data types, and they can be scalar or multi-valued.
Figure A

AWS Management console (Click the image to enlarge.)

As an example, we created a DynamoDB table called TechRepublicTest, which is initiated in Figure B. Once Create Table is selected, the window in Figure C is presented to name the table and define a primary key name and data type. Figure D is the next window presented to define the throughput of the application — the checkbox allows you to let Amazon provide assistance. Once complete, Figure E appears to define any alarms/notifications. Once complete, the page in Figure F is displayed showing the table is created. With the table in place, it can be used in your code.
Figure B

The first step in using DynamoDB – create a table. (Click the image to enlarge.)

Figure C

The second step in creating a DynamoDB table – naming. (Click the image to enlarge.)

Figure D

The third step in creating a DynamoDB table – provisioning. (Click the image to enlarge.)

Figure E

The final step in creating a DynamoDB table – alarms. (Click the image to enlarge.)

Figure F

Viewing the DynamoDB table within a management console. (Click the image to enlarge.)

Interfacing with .NET

The AWS .NET SDK makes it easy to utilize the many Web services available from Amazon within your .NET code — this includes DynamoDB, SimpleDB, S3, and so forth. The installation of the SDK makes all of the libraries available. Also, the download includes plenty of examples.

One of the integral pieces of using AWS features in your code is your AWS access and secret key values. These are easily retrieved via the AWS management console page by choosing Security Credentials from the My Account/Console dropdown in the upper right of the screen.

With credentials in hand, you can look at the DynamoDB .NET code sample included with the download (called AmazonDynamoDB_Sample). The first part of utilizing DynamoDB is using your credentials to create an instance of the AmazonDynamoDB object to work with database objects.

AmazonSecurityTokenServiceClient stsClient = new AmazonSecurityTokenServiceClient();

RefreshingSessionAWSCredentials sessionCredentials = new RefreshingSessionAWSCredentials(stsClient);

AmazonDynamoDB client = new AmazonDynamoDBClient(sessionCredentials);

Once you have an instance of the client, you can work with database objects or data. The following snippet creates another table called CNetSites with two attributes: Title and URL.

client.CreateTable(new CreateTableRequest {

TableName = "CNetSites", ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 5, WriteCapacityUnits = 5}, KeySchema = new KeySchema {

HashKeyElement = new KeySchemaElement { AttributeName = "Title", AttributeType = "S" }, RangeKeyElement = new KeySchemaElement { AttributeName = "URL", AttributeType = "S" } } });

You can dig further into the example code included with the SDK to get a better feel for how to use the various objects and services within your code. You are not limited to .NET; there are SDK’s available for Java and PHP as well.

Another good service from Amazon

When it comes to e-commerce, does anybody do it better than Amazon? I think it’s great that the company opens these services that have been fully tested within its own demanding environment, so I can utilize a backend NoSQL environment via DynamoDB in my application and focus on the coding not the infrastructure.

I am new to DynamoDB, so if you’re using it, please share your experiences with the cloud service — positive or negative — in the discussion.

Keep your engineering skills up to date by signing up for TechRepublic’s free Software Engineer newsletter, delivered each Tuesday.