Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon DynamoDB putItem returning null

I am using AmazonDynamoDBClient putItem method to insert item in DB. return type of putItem is PutItemResult but i m getting it as null.

AmazonDynamoDBClient client = new AmazonDynamoDBClient();
PutItemRequest r = new PutItemRequest();
r.addItemEntry("custId",new Attribute Value("101"));
PutItemResult result = client.putItem(r);
//result is null

Item is inserted successfully in DB but why result is getting as null?

like image 735
Rohit Chouhan Avatar asked Sep 01 '25 01:09

Rohit Chouhan


1 Answers

Please specify the RETURN_VALUE based on your requirement. The default is NONE.

ReturnValues — (String) Use ReturnValues if you want to get the item attributes as they appeared before they were updated with the PutItem request. For PutItem, the valid values are:

NONE - If ReturnValues is not specified, or if its value is NONE, then nothing is returned. (This setting is the default for ReturnValues.) ALL_OLD - If PutItem overwrote an attribute name-value pair, then the content of the old item is returned. Note: The ReturnValues parameter is used by several DynamoDB operations; however, PutItem does not recognize any values other than NONE or ALL_OLD.

From API docs:-

public PutItemRequest(String tableName,
                      Map<String,AttributeValue> item,
                      String returnValues)

Set return values

The ReturnValues parameter is used by several DynamoDB operations; however, PutItem does not recognize any values other than NONE or ALL_OLD.

ALL_NEW, UPDATED_NEW and UPDATED_OLD are for UpdateItem operations.

UPDATED_OLD - Returns only the updated attributes, as they appeared before the UpdateItem operation.

ALL_NEW - Returns all of the attributes of the item, as they appear after the UpdateItem operation.

UPDATED_NEW - Returns only the updated attributes, as they appear after the UpdateItem operation.

like image 122
notionquest Avatar answered Sep 03 '25 17:09

notionquest