Lenny D.
Lenny D.

Reputation: 298

Using requests or straight DynamoDB object to retrieve items from table?

I'm currently working with the DynamoDB AWS API and just found two different ways of doing apparently the same thing, I was actually wondering if there is any performance or benefit in user one instead of another.

My current scenario is restricted to just a table, so I will be only manipulating that one without going any further.

Is there any benefit from using this (which I think that in my scenario is simpler that forming a request every single time I want to check key existence, and I can also have a fixed Table object to request any time I need to)...

    AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
    DynamoDB dynamoDB = new DynamoDB(client);

    Table table = dynamoDB.getTable("my-table");
    table.getItem("sample");

... with this one?

    AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();

    HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("Artist", new AttributeValue().withS("sample1"));
    key.put("SongTitle", new AttributeValue().withS("sample2"));

    GetItemRequest request = new GetItemRequest()
        .withTableName("my-table")
        .withKey(key);

I've taken the code from the actual examples in the AWS website.

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.SDKs.Interfaces.LowLevel.html

https://docs.aws.amazon.com/en_en/amazondynamodb/latest/developerguide/JavaDocumentAPIWorkingWithTables.html#JavaDocumentAPIListTables

Upvotes: 0

Views: 67

Answers (1)

Matthew Pope
Matthew Pope

Reputation: 7669

Table is more or less a light-weight wrapper around the DynamoDB client object. (You can see this by looking at its source code on Guthub.) You can use whichever one you think makes your code the most readable and maintainable.

Upvotes: 1

Related Questions