Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all the table items from DynamoDB table using Java High Level API

I implemented scan operation using in dynamodb table using dynamodbmapper, but I'm not getting all the results. Scan returns different number of items, whenever I run my program.

Code snippet :

DyanmoDBScanExpression scanExpression = new DynamoDBScanExpression();
List<Books> scanResult = mapper.scan(Books.class, scanExpression);

I investigated into it, and found out about the limit of the items scan returns. But I couln't find a way to get all the items from the table using mapper! Is there a way so I can loop through all the items of the table. I have set enough heap memory in JVM so there won't be memory issues.

like image 769
dushyantashu Avatar asked Jul 17 '26 21:07

dushyantashu


1 Answers

In java use the DynamoDBScanExpression without any filter,

// Change to your Table_Name (you can load dynamically from lambda env as well)
DynamoDBMapperConfig mapperConfig = new DynamoDBMapperConfig.Builder().withTableNameOverride(DynamoDBMapperConfig.TableNameOverride.withTableNameReplacement("Table_Name")).build();

DynamoDBMapper mapper = new DynamoDBMapper(client, mapperConfig);

DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();

// Change to your model class   
List < ParticipantReport > scanResult = mapper.scan(ParticipantReport.class, scanExpression);



// Check the count and iterate the list and perform as desired.
scanResult.size();
like image 77
Jacob Joy Avatar answered Jul 20 '26 09:07

Jacob Joy