我如何在dynamodb参数中使用字符串var,总是获得'“ String”'而不是“ String” nodejs lambda

时间:2019-09-20 21:36:33

标签: node.js json string amazon-dynamodb

在我的参数@AWS Lambda node.js中始终获取“ String”而不是“ String”,有什么想法吗? (nodejs10.x)

从dynamodb流中获取带有字符串(userId)的记录,想要使用该字符串从dynamodb中读取更多项。

event.Records.forEach((record) => {
   if (record.eventName == 'INSERT') {
        var userId = JSON.stringify(record.dynamodb.NewImage.userId.S);
        console.log('userId: ', userId);
        // log: userId: "userid1234"

        const params = {
          Key: {
            userId: {S: userId},
          },
          TableName: "test-table",
        };

        console.log("params ", params);
        //params { userId: '"userid1234"' },
        // not working

        var pa = {
          TableName: "test-table",
          Key: {
            'userId' : {"S": "userId"},
          },
        };

        console.log("pa ", pa);
        //pa { userId: 'userid1234' },
        //working

        dbCon.getItem(pa, function(err, data) {
          if (err) {
            console.log("Error", err);
          } else {
            console.log("Success", data.Item);
          }
        });
      }

“字符串”而不是“字符串”,我该怎么做?

0 个答案:

没有答案