- Newest
- Most votes
- Most comments
This discrepancy between DynamoDB Local and the live DynamoDB service is likely due to differences in implementation between the two environments.
When executing a Query operation with a Limit parameter:
- The live DynamoDB service will only return LastEvaluatedKey if there are more results available beyond what was returned in the current response
- DynamoDB Local appears to be returning LastEvaluatedKey regardless of whether there are additional results that match your query
This behavior is similar to a known issue with PartiQL SELECT statements in DynamoDB Local, where there are inconsistencies between the local implementation and the live service when using ordering and limit parameters.
The most reliable approach is to trust the behavior of the live DynamoDB service as the correct implementation. In your case, if the cloud service isn't returning a LastEvaluatedKey, it means there are no more items that match your query criteria beyond what was returned.
When developing locally, you may need to account for these differences in your pagination logic. For example, you might need to check if there are actually more results available rather than relying solely on the presence of LastEvaluatedKey.
Sources
ExecuteStatement with Limit on DynamoDB Local returns wrong result set when using descending ordering | AWS re:Post
Query - Amazon DynamoDB
Hello,
There are certain differences in the implementations of Local and Remote setup of DynamoDB that would lead to this particular case but this is within the expectations of how DynamoDB is supposed to function.
If LastEvaluatedKey is empty, then the "last page" of results has been processed and there is no more data to be retrieved.
If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in the result set. The only way to know when you have reached the end of the result set is when LastEvaluatedKey is empty.
reference docs - API_Query_ResponseSyntax
To learn more about how to handle the case where LastEvaluatedKey is returned please refer to - Paginating table query results in DynamoDB
