Posted: 22/Jan/2024
The Query
API returns the result set size to 1 MB
. Use ExclusiveStartKey
and LastEvaluatedKey
elements to paginate over large result sets. You can also reduce page size by limiting the number of items in the result set, with the Limit
parameter of the Query
operation.
Here is an example:
funcpaginatedQuery(searchCriteriastring,pageSizeint32){currPage:=1varexclusiveStartKeymap[string]types.AttributeValuefor{resp,_:=client.Query(context.Background(),&dynamodb.QueryInput{TableName:aws.String(tableName),KeyConditionExpression:aws.String("ForumName = :name"),ExpressionAttributeValues:map[string]types.AttributeValue{":name":&types.AttributeValueMemberS{Value:searchCriteria},},Limit:aws.Int32(pageSize),ExclusiveStartKey:exclusiveStartKey,})ifresp.LastEvaluatedKey==nil{return}currPage++exclusiveStartKey=resp.LastEvaluatedKey}}
Recommended reading - Query Pagination