How to fetch/scan all items from `AWS dynamodb` using node.js

This is working for me: export const scanTable = async (tableName) => { const params = { TableName: tableName, }; const scanResults = []; const items; do{ items = await documentClient.scan(params).promise(); items.Items.forEach((item) => scanResults.push(item)); params.ExclusiveStartKey = items.LastEvaluatedKey; }while(typeof items.LastEvaluatedKey !== “undefined”); return scanResults; };

Complete scan of dynamoDb with boto3

I think the Amazon DynamoDB documentation regarding table scanning answers your question. In short, you’ll need to check for LastEvaluatedKey in the response. Here is an example using your code: import boto3 dynamodb = boto3.resource(‘dynamodb’, aws_session_token=aws_session_token, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name=region ) table = dynamodb.Table(‘widgetsTableName’) response = table.scan() data = response[‘Items’] while ‘LastEvaluatedKey’ in response: response = … Read more