so I'm trying to scan a dynamodb table using lastkeyevaluated, limit and filterexpression. I also want to take the returned lastevaluatedkey, filterexpression and limit from one dynamodb and add it to a new dynamodb table. This is my code right now
package dev.example;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.ScanRequest;
import com.amazonaws.services.dynamodbv2.model.ScanResult;
import java.util.Map;
public class ScanTable {
static AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
//static DynamoDB dynamoDB = new DynamoDB(client);
public static void scan()
{
Map<String, AttributeValue> lastKeyEvaluated = null;
String status = "open";
do {
ScanRequest scanRequest = new ScanRequest()
.withTableName("tablename")
.withLimit(10)
.withExclusiveStartKey(lastKeyEvaluated)
.withFilterExpression(status);
ScanResult result = client.scan(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()){
System.out.println(item);
}
lastKeyEvaluated = result.getLastEvaluatedKey();
} while (lastKeyEvaluated == null);
}
public static void main(String[] args) throws Exception {
scan();
}
}
I'm not sure how to do that.
For Scanning the table take a look at these docs . This shows how to set the Limit, FilterExpression and how to paginate.
For adding the returned values, take a look at these docs which show you how to do a PutItem request to save the values to a new table.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.