Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should one use each of the various DynamoDB API clients?

I am working on a personal project that makes extensive use of DynamoDB, which I have never used before, and I find myself running into the following question: "Which DynamoDB client object should I use for this read/write?"

For example, I have already encountered three different classes that offer some degree of write capability: AmazonDynamoDBClient, DynamoDB, and Table (See below for link directions). They are built on top of each other, to the best of my understanding, as you can get a Table like the following:

Table table = new DynamoDB(new AmazonDynamoDBClient()).getTable("TableName");

However, when I want to perform a write (be it 'update' or 'put'), AmazonDynamoDBClient offers

c.putItem(PutItemRequest r);
//or
c.updateItem(UpdateItemRequest r);
//or
c.batchWriteItem(BatchWriteItemRequest r);

DynamoDB offers

d.batchWriteItem(BatchWriteItemSpec s);

and Table offers

t.putItem(Item);
// or
t.putItem(PutItemSpec s);
// or
t.updateItem(UpdateItemSpec s);

As you can see, there is a lot of overlap in terms of how one could use each class to write to a table. Furthermore, there are difference types of request objects for the difference client objects (eg. the 'Request' family and the 'Spec' family), which each have very different approaches to populating their options. This prevents me from using one request and then passing it to whatever client my classes happen to have on hand.

How should I go about choosing when to use which client (and associated methods and request objects)? My initial assessment says to simply use the AmazonDynamoDB client by itself, as it is the simplest object that offers all of my required functionality (at first glance).

NOTE: I don't have a high-enough reputation yet to link to all 3 classes, but Table can be accessed from the DynamoDB API page's getTable() method return type.

like image 778
S.Denney Avatar asked Oct 06 '15 18:10

S.Denney


1 Answers

see:

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/AboutJava.html

The low level is if you want to basically do all the DDB calls yourself and gives you the most control. The high-level maps things into Java objects that you use directly and will marshall the operations you are doing to the lower level. The document one is sort-of new.

The difference between put and update is that put needs the whole body of the item where in the case of the update you need only attributes that are changing.

Batch operations are usually done for latency purposes (i.e. updating 300 records at a time vs updating a record 300 times).

If it's just for a pet project I would recommend starting with the low-level api so that you can understand what Dynamo is and can do at API level.

like image 170
Mircea Avatar answered Oct 28 '22 17:10

Mircea