Facing issue: scan dynamo DB

故事扮演 提交于 2019-12-24 11:28:55

问题


I've created apis in nodejs to scan and query dynamoDB table(contains 70K records). I'm stuck with scan api. I've two APIs for scan - 1. Scanning table with limit of 500 - getting proper response 2. Scanning table without any limit - response code 403

And if I'm calling the same query without any limit through cli, getting full response.

Not getting what's the problem.

api.get('/deviceData', function (request) { // GET all users
  return dynamoDb.scan({ 
        TableName: 'student', 
        Limit: 500
    }).promise()
      .then(response => response.Items);
});

api.get('/deviceData-scan', function (request) { // GET all users
  return dynamoDb.scan({ 
        TableName: 'student'
    }).promise()
      .then(response => response.Items);
});

回答1:


Please check how to use scan multiple time its help you.

function getData() {
    let params = {
      TableName: 'student'
    };
    let finalResult = [];
      let queryExecute = function () {
        documentClient.scan(params, function (err, result) {
          if (err) {
            console.log('failure', err);
          } else {
            finalResult = finalResult.concat(result.Items);
            // check if more data exists.
            if (result.LastEvaluatedKey) {
              params.ExclusiveStartKey = result.LastEvaluatedKey;
              queryExecute();
            } else {
              console.log('all data', finalResult);
            }
          }
        });
      };
      queryExecute();
  },


来源:https://stackoverflow.com/questions/52554652/facing-issue-scan-dynamo-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!