Get All Items from DynamoDB Using Java (Guide w/ Code Examples)
![Rafal Wilinski](https://pbs.twimg.com/profile_images/1390706809548197895/SVCKpLNE_400x400.png)
Provided by Rafal Wilinski
In this example, a ScanRequest
is created and set to retrieve data from the "MyTable" table. The ScanResult
is retrieved and stored in a variable called result
. The Scan
operation is called in a do-while loop. The loop continues as long as the LastEvaluatedKey
attribute of the ScanResult
object is not null. This attribute is present when the Scan
operation has been paginated and contains the primary key of the last item on the current page of results. The setExclusiveStartKey
method is used to set the primary key to start the next scan operation so that the next page of results will be retrieved.
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; import com.amazonaws.services.dynamodbv2.model.ScanRequest; import com.amazonaws.services.dynamodbv2.model.ScanResult; public class GetAllItemsExample { public static void main(String[] args) { AmazonDynamoDB client = AmazonDynamoDBClientBuilder.defaultClient(); ScanRequest scanRequest = new ScanRequest().withTableName("MyTable"); ScanResult result; do { result = client.scan(scanRequest); result.getItems().forEach(item -> System.out.println(item)); scanRequest.setExclusiveStartKey(result.getLastEvaluatedKey()); } while (result.getLastEvaluatedKey() != null); } }
Similar Code Examples
- Update Expression in DynamoDB Using Java
- Delete Table in DynamoDB Using Java
- Batch Insert in DynamoDB Using Java
- Get in DynamoDB Using Java
- Delete in DynamoDB Using Java
- Delete All Using DynamoDB Mapper
- Batch Write Using DynamoDB Mapper
- Batch Write Item in DynamoDB Using Java
- Batch Read in DynamoDB Using Java
- Remove Attribute in DynamoDB Using Java
- Delete All Items in DynamoDB Using Java
- Batch Save Using DynamoDB Mapper
- Query Hash Key Only in DynamoDB Using Java
- Update Multiple Attributes in DynamoDB Using Java
- Get Item Request in DynamoDB Using Java
Login to the AWS Console less. Use Dynobase.
First 7 days are. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase