dynobase-icon
Dynobase

Batch Read in DynamoDB Using Java (Guide w/ Code Examples)

Rafal Wilinski

Provided by Rafal Wilinski

To perform a batch GetItem request in DynamoDB, you can use the AmazonDynamoDB#batchGetItem method. This method allows you to retrieve multiple items from one or more tables in a single request.

AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build(); Map<String, KeysAndAttributes> requestItems = new HashMap<>(); // Add a map entry for each table from which you want to retrieve items KeysAndAttributes keysAndAttributes = new KeysAndAttributes(); // Add a list of primary key attribute values for the items you want to retrieve keysAndAttributes.setKeys( Arrays.asList( new PrimaryKey("PK", 1), new PrimaryKey("PK", 2) ) ); // Add optional attributes to retrieve for each item keysAndAttributes.setAttributesToGet(Arrays.asList("attr1", "attr2")); requestItems.put("myTable", keysAndAttributes); BatchGetItemRequest request = new BatchGetItemRequest() .withRequestItems(requestItems); BatchGetItemResult result = client.batchGetItem(request);

Login to the AWS Console less. Use Dynobase.

Try 7-day free trial. No credit card needed.

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2024 Dynobase
+
Dynobase - DynamoDB Swiss Army Knife
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.