Limit parameter does not work in paginateScan and paginateQuery in @aws-sdk/lib-dynamodb #5967
Replies: 2 comments 1 reply
-
Hi @cm-rwakatsuki , When you are using a paginator if you want to specify the max results per page, you need to use the paginator config's const paginator = paginateScan(
{
client: ddbDocClient,
+ pageSize: 1 // functions similarly to Limit
},
{
TableName: SAMPLE_TABLE_NAME,
- Limit: 1, // DOES NOT WORK
} By specifying the pageSize parameter we can see the results more accurately printed one result per page:
If you want to limit the total returned results you need to specify the number of pages * the number of results per page = total results returned: async function scanTableWithLimit() {
const ddbDocClient = DynamoDBDocumentClient.from(client);
const paginator = paginateScan(
{
client: ddbDocClient,
pageSize: 1,
},
{
TableName: tableName,
}
);
const LIMIT = 2;
let count = 0;
for await (const page of paginator) {
console.log(`Received page with ${page.Items.length} items`);
console.log(page.Items);
if (++count >= LIMIT) {
break;
}
}
} Will result in a total of 2 results returned (2 pages, 1 result per page):
==== Non pagination request with async function scanTableWithLimit() {
try {
const response = await client.send(new ScanCommand({
TableName: tableName,
Limit: 1
}));
console.log(response.Items);
} catch (error) {
console.error(error);
}
} This will indeed return only 1 result:
I hope this clarifies things. All the best, |
Beta Was this translation helpful? Give feedback.
-
@RanVaknin I too faced similar issue. But here, I expect to get 25 results for every request I send to DynamoDb. If I use |
Beta Was this translation helpful? Give feedback.
-
Checkboxes for prior research
Describe the bug
It is possible to specify limit parameters in paginateScan and paginateQuery in @aws-sdk/lib-dynamodb, but it makes no sense. All data from the table is queried or scanned regardless of the Limit value you specify.
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
Node.js 20.x
Reproduction Steps
This is the code that actually causes the problem.
This is the sample data file
src/tableData/table1.csv
stored in the table.Create the Lambad function and DynamoDB table that causes the event using AWS CDK.
Deploy resources with CDK commands.
Observed Behavior
When I run the Lambda function built above, all data on the table will be retrieved and output to the logs, regardless of the value specified for the Limit parameter of paginateScan.
Expected Behavior
The maximum number of data specified by the Limit parameter is returned.
Possible Solution
No response
Additional Information/Context
No response
Beta Was this translation helpful? Give feedback.
All reactions