简体   繁体   English

如何解决这不是一个功能nodejs

[英]How to fix this is not a function nodejs

I am following this article from medium https://blog.bitsrc.io/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e 我正在从中等https://blog.bitsrc.io/serverless-backend-using-aws-lambda-hands-on-guide-31806ceb735e阅读本文

Everything works except when I attempt to add a record to the DynamoDB I get an error that say "this is not a function" 一切正常,除了当我尝试向DynamoDB添加记录时,我收到一条错误消息,提示“这不是函数”

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

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

const uuid = require ("uuid");

module.exports.myHero = async (event) => {

    const data = JSON.parse(event.body);

    const params = {

        TableName: "myHeros",
        Item: {

            id: uuid(),
            name: data.name,
            checked: false
        }
    };

    await client.put(params).promise();

    return {

        statusCode: 200,
        body: JSON.stringify(data)
    };
};
{
    "errorMessage": "client.put(...).promise is not a function",
    "errorType": "TypeError",
    "stackTrace": [
        "module.exports.myHero (/var/task/create.js:30:27)"
    ]
}

在初始化dynamodb客户端新的AWS.DynamoDB.DocumentClient()时,请将选项(至少是区域参数)传递给DocumentClient函数。

In almost all cases, when you call a method xyz() on an AWS client object and it fails with 'xyz is not a function', the problem is that you are using an old version of an SDK that does not actually support that method. 在几乎所有情况下,当您在AWS客户端对象上调用方法xyz()且失败并显示“ xyz不是函数”时,问题在于您使用的是旧版SDK,而该版本实际上并不支持该方法。

Upgrading to the latest AWS SDK version will fix this problem. 升级到最新的AWS开发工具包版本将解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM