Skip to content

Instantly share code, notes, and snippets.

@notionquest
Created May 25, 2017 15:34
Show Gist options
  • Save notionquest/128109e7d97933f2f266c2619f3dcf66 to your computer and use it in GitHub Desktop.
Save notionquest/128109e7d97933f2f266c2619f3dcf66 to your computer and use it in GitHub Desktop.
AWS DynamoDB Full Table Scan using Java
import java.util.List;
import java.util.Map;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ScanRequest;
import com.amazonaws.services.dynamodbv2.model.ScanResult;
public class ScanTable {
public static void main(String[] args) {
AmazonDynamoDB amazonDynamoDB = AmazonDynamoDBClientBuilder.standard()
.withEndpointConfiguration(new EndpointConfiguration("http://localhost:8000", "us-east-1")).build();
ScanRequest scanRequest = new ScanRequest().withTableName("Movies");
Map<String, AttributeValue> lastKey = null;
do {
ScanResult scanResult = amazonDynamoDB.scan(scanRequest);
List<Map<String, AttributeValue>> results = scanResult.getItems();
// You can get the results here
results.stream().forEach(System.out::println);
lastKey = scanResult.getLastEvaluatedKey();
scanRequest.setExclusiveStartKey(lastKey);
} while (lastKey != null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment