I want to use PartiQL to query DynamoDB and paginate the result.
According to the doc https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#executeStatement-property. The query result gives lastEvaluatedKey
The doc says If LastEvaluatedKey is present in the response, you need to paginate the result set.
But the doc does not way how to paginate the result. executeStatement
does not take lastEvaluatedKey
as a parameter.
I want to use Limit
to get 10 items at a time. Like 10 items, the next page get another 10 items.
Is this possible with executeStatement
?
CodePudding user response:
You can pass a NextToken
to the ExecuteStatement
as per https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ExecuteStatement.html
Search for NextToken
on the docs link you used in the question.
Please beware the limit applies BEFORE any filtering. There's no way to ask for 10 post-filtered items.
CodePudding user response:
If you use the query
API, then you get the next page by moving LastEvaluatedKey
from the response into ExclusiveStartKey
in the next request.
The executeStatement
API doesn't seem to support the ExclusiveStartKey
parameter -- disappointing. That means that you'll have to incorporate the equivalent condition that key > LastEvaluatedKey
into your query. You can get the range key value out of the LastEvaluatedKey
object.