I don't know PHP, but here is a Java 8 example ran against DynamoDB Local with a dependency on compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.10.20'. This shows how Limit (mostly, it doesn't show how filters effect the returned items), LastEvaluatedKey, and ExclusiveStartKey work. You can see how the parameters are set, and compare it to the PHP example:
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.document.Item;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType;
import com.amazonaws.services.dynamodbv2.model.ScanRequest;
import com.amazonaws.services.dynamodbv2.model.ScanResult;
import com.amazonaws.services.dynamodbv2.util.Tables;
import com.google.common.collect.ImmutableList;
import java.util.Map;
public class ScanExample {
private static final String TABLE_NAME = "test_table";
private static final String HASH_ATTR_NAME = "hash";
public static void main(String[] args) throws InterruptedException {
AWSCredentials awsCredentials = new BasicAWSCredentials("key", "secret");
AmazonDynamoDB dynamoDBClient = new AmazonDynamoDBClient(awsCredentials);
dynamoDBClient.setEndpoint("http://localhost:4000");
if (Tables.doesTableExist(dynamoDBClient, TABLE_NAME)) {
dynamoDBClient.deleteTable(TABLE_NAME);
}
CreateTableRequest createTableRequest = new CreateTableRequest();
createTableRequest.setTableName(TABLE_NAME);
createTableRequest.setProvisionedThroughput(new ProvisionedThroughput(50l, 50l));
createTableRequest.withKeySchema(
ImmutableList.of(new KeySchemaElement(HASH_ATTR_NAME, KeyType.HASH)))
.withAttributeDefinitions(ImmutableList.of(
new AttributeDefinition(HASH_ATTR_NAME, ScalarAttributeType.N))
);
dynamoDBClient.createTable(createTableRequest);
Tables.awaitTableToBecomeActive(dynamoDBClient, TABLE_NAME);
final Table table = new DynamoDB(dynamoDBClient).getTable(TABLE_NAME);
createItems(table, 8);
final int limit = 3;
performScan(dynamoDBClient, limit);
}
private static void performScan(final AmazonDynamoDB client, final int limit) {
ScanRequest scanRequest = new ScanRequest(TABLE_NAME)
.withLimit(limit);
Map<String, AttributeValue> exclusiveStartKey = null;
do {
final ScanResult scanResult = client.scan(scanRequest);
System.out.println("With exclusiveStartKey=" + exclusiveStartKey);
scanResult.getItems().forEach(System.out::println);
exclusiveStartKey = scanResult.getLastEvaluatedKey();
System.out.println("Result lastEvaluatedKey=" + exclusiveStartKey);
// Reusing same request object, just setting the start key
scanRequest.setExclusiveStartKey(exclusiveStartKey);
System.out.println();
} while(exclusiveStartKey != null);
}
private static void createItems(final Table table, final int n) {
for (int i = 0; i < n; i++) {
table.putItem(new Item().withNumber(HASH_ATTR_NAME, i));
}
}
}
Example output:
With exclusiveStartKey=null
{hash={N: 2,}}
{hash={N: 1,}}
{hash={N: 3,}}
Result lastEvaluatedKey={hash={N: 3,}}
With exclusiveStartKey={hash={N: 3,}}
{hash={N: 5,}}
{hash={N: 7,}}
{hash={N: 0,}}
Result lastEvaluatedKey={hash={N: 0,}}
With exclusiveStartKey={hash={N: 0,}}
{hash={N: 6,}}
{hash={N: 4,}}
Result lastEvaluatedKey=null