Dynamo表扫描在大表上悄然失败

时间:2020-09-06 01:52:09

标签: amazon-dynamodb dynamodb-queries

我正在尝试扫描DynamoDB表并将其内容打印到JS文件中。

我的表格大约有100,000行

我的代码似乎可以在小型表上运行,但是当我在大型表上尝试运行时,它在API调用中未返回任何内容,这似乎使我难以捉摸,但是错误只是记录为空对象!

const AWS = require("aws-sdk");

class DynamoDB {
    constructor() {
        this.region = 'eu-west-1';
        this.endpoint = 'https://dynamodb.eu-west-1.amazonaws.com';
        this.ddbService = new AWS.DynamoDB({
            apiVersion: '2012-08-10',
            endpoint: this.endpoint,
            region: this.region
        });
        this.docClient = new AWS.DynamoDB.DocumentClient({
            service: this.ddbService
        });
    }

     async dbRead(tableName) {
         let params = {
             TableName: tableName,
         };
        let promise = this.docClient.scan(params).promise();
        let result = await promise;
        let data = result.Items;
      
        if (result.LastEvaluatedKey) {
            
            params.ExclusiveStartKey = result.LastEvaluatedKey;
            data = data.concat(await dbRead(params));
        }

        return data;
    }
}

module.exports = DynamoDB;



const Dynamo = require("./dynamo");
const $ = new Dynamo();
const fs = require("fs");

const tableData = {
    PLAYS: {
        tableName: "Plays",
    }
};

(async () => {
    try {
        var data = await $.dbRead(tableData.PLAYS.tableName);
        fs.writeFileSync("dump.js", JSON.stringify(data, null, 2));
    } catch (e) {
        console.log(JSON.stringify(e)) // This just logs an empty object!
    }
})();

0 个答案:

没有答案