Nodejs 10:为什么 DynamoDB 多次放置函数成功

Nodejs 10: Why does DynamoDB put function giving success multiple times

我正在编写节点 js 10.x lambda 函数以将详细信息放入 DynamoDB table。

Below is code

const AWS = require('aws-sdk');
var db = new AWS.DynamoDB.DocumentClient();
var tableName="xyz";

exports.handler = async (event) => {
    // TODO implement
    console.log("Event: "+ JSON.stringify(event));
    
    var response = {
        statusCode: 200,
        "headers": {
            "Access-Control-Allow-Origin" : "*",
            "Access-Control-Allow-Credentials" : true
        },
    };
    await db.put({
        TableName: tableName,
        Item: {
            userid: event.userid,
        }
    }, (error, data) => {      
        if (error) {
            console.log("error:"+ error);
        }
        else{
            console.log("Success");
        }
    }).promise();
    
    return response;
};

I am getting kind on random number of success return

Output execution 1

2019-11-07T07:03:45.388Z    f451dfc1-01ea-41d0-a998-945cb0f18be1    INFO    Success
2019-11-07T07:03:45.510Z    f451dfc1-01ea-41d0-a998-945cb0f18be1    INFO    Success
2019-11-07T07:03:45.511Z    f451dfc1-01ea-41d0-a998-945cb0f18be1    INFO    Success

Output execution 2

2019-11-07T07:08:19.270Z    3ce51f5d-bbbc-4dd6-b46f-2149ee9bb9cf    INFO    Success

Output execution 3

2019-11-07T07:08:27.410Z    2625bba5-b8e1-40e4-8704-7c0d486f6dff    INFO    Success
2019-11-07T07:08:27.431Z    2625bba5-b8e1-40e4-8704-7c0d486f6dff    INFO    Success

** 有谁知道这个问题的原因吗?

我对 node js 比较陌生10.x。所以如果我遗漏了代码中的某些内容,请帮助我 **

您同时使用了一个,请移除回调。

你可以试试

exports.handler = async (event, context) => {
    const params = {
        TableName: tableName,
        Item: {
            userid: event.userid,
        }
    };

    try {
        const data = await dynamoDB.put(params).promise();
        console.log("Data: ", data);
    } catch(error) {
        console.error("Error:", error);
    }
}