title: What is the easiest way to implement offset and limit in AWS DynamoDB?
body: <p>I am currently working on DynamoDB and I saw there is no inbuilt function to put offset and limit like SQL queries. The only thing I have seen is get the <code>lastEvaluatedKey</code> and pass as <code>exclusiveStartKey</code>. But my problem is according to our scenarios we can't get the <code>lastEvaluatedKey</code> and populate because we are <code>sorting</code> data and <code>parallel-stream</code> the data.</p>
  <p>So there will be issues and hard points. I just need to know what is the clean way or are there any best way we can pass the offset and limit and get the data without iterating over all the data. Because right now even though there is offset and limit put to <code>bound-iterator</code> it is inside get and iterating all the data in DynamoDB which consumes lots of read capacities even though we don't need the other data.</p>
  <pre><code>Map&lt;String, AttributeValue&gt; valueMap = new HashMap&lt;&gt;();
  valueMap.put(&quot;:v1&quot;, new AttributeValue().withS(id));
  
  Map&lt;String, String&gt; nameMap = new HashMap&lt;&gt;();
  nameMap.put(&quot;#PK&quot;, &quot;PK&quot;);
  
  DynamoDBQueryExpression&lt;TestClass&gt; expression = new DynamoDBQueryExpression&lt;TestClass&gt;()
  .withKeyConditionExpression(&quot;#PK = :v1&quot;)
  .withExpressionAttributeNames(nameMap)
  .withExpressionAttributeValues(valueMap)
  .withConsistentRead(false);
  
  PaginatedQueryList&lt;TestClass&gt; testList = dynamoDBMapper.query(TestClass.class, expression);
  Iterator&lt;TestClass&gt; iterator = IteratorUtils.boundedIterator(testList.iterator(), offset, limit);
  return IteratorUtils.toList(iterator);
  </code></pre>
  <p>What will be the best way to handle this issue?</p>