lambda function outputted an error "e is not a function"

Viewed 974

created two lambda functions by serverless-framework. first function "record-song-vote" writes DynamoDB, it works fine. second function "get-vote-counts" reads all records from DynamoDB, but it continually return error:

{
  "errorType": "TypeError",
  "errorMessage": "e is not a function",
  "trace": [
    "TypeError: e is not a function",
    "    at Runtime.handler (/var/task/serverless_sdk/index.js:9:131872)",
    "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
  ]
}

function get-vote-counts:

'use strict';
const AWS = require("aws-sdk");

const dynamodb = new AWS.DynamoDB.DocumentClient();

module.exports.handler = async event => {
    const params = {
        TableName: process.env.DYNAMODB_TABLE
    };

    const result = await dynamodb.scan(params, (error, data) => {
        if (error) {
            console.error("Unable to update item. Error JSON:", JSON.stringify(error, null, 2));
        } else {
            console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2));
        }
    }).promise();

    const outputData = result["Items"].map((item) => {
        return {
            songName: item['songName'],
            votes: item['votes']
        }
    });

    return {
        "statusCode": 200,
        "headers": {
            "Access-Control-Allow-Origin": "*"
        },
        "body": JSON.stringify(outputData)
    }
};

I have tried to comment all line in this file. but I still got same error. does anybody have idea?

0 Answers
Related