Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js AWS Lambda TypeError:回调不是函数_Node.js_Aws Lambda_Twilio - Fatal编程技术网

Node.js AWS Lambda TypeError:回调不是函数

Node.js AWS Lambda TypeError:回调不是函数,node.js,aws-lambda,twilio,Node.js,Aws Lambda,Twilio,我试图在AWS lambda中创建twilio访问令牌,但我得到错误“回调不是函数”。我怎样才能修好它 const AccessToken = require('twilio').jwt.AccessToken; const VoiceGrant = AccessToken.VoiceGrant; exports.generateToken = function(identity, callback) { // Used when generating any

我试图在AWS lambda中创建twilio访问令牌,但我得到错误“回调不是函数”。我怎样才能修好它

const AccessToken = require('twilio').jwt.AccessToken;
    const VoiceGrant = AccessToken.VoiceGrant;

    exports.generateToken = function(identity, callback) {
        // Used when generating any kind of tokens
        const accountSid = 'xxxxxxxxx';
        const apiKey = 'xxxxx';
        const apiSecret = 'xxx';

        // Used specifically for creating Voice tokens
        const pushCredSid = 'xxx';
        const outgoingApplicationSid = 'xxxxx';

        // Create an access token which we will sign and return to the client,
        // containing the grant we just created
        const voiceGrant = new VoiceGrant({
            outgoingApplicationSid: outgoingApplicationSid,
            pushCredentialSid: pushCredSid
        });

        // Create an access token which we will sign and return to the client,
        // containing the grant we just created
        const token = new AccessToken(accountSid, apiKey, apiSecret);
        token.addGrant(voiceGrant);
        token.identity = identity;
        console.log('Token:' + token.toJwt());
        callback(null, token.toJwt());
    };

正如罗兰·斯塔克所说,将这个
exports.generateToken=function(identity,callback)
更改为
exports.generateToken=function(event,context,callback)
是值得的,一切都会正常工作。

嘿,这行
callback(null,token.toJwt())?mh不是调用
generateToken
的重要部分?@RolandStarke这是一个重要部分,因为在这里结果应该返回,我做了另外两个lambda函数,它们工作得很好,但是在这里我不断得到我上面写的错误。mh是不是AWS lambda要求你有3个参数?从
exports.myHandler=function(event,context,callback){
@RolandStarke No,不一定有三个参数。我的意思是,如果要使用回调,就需要使用三个参数。(是的,参数名可能有一些魔力。但一般来说,javascript中没有命名参数,所以我会尝试用3个参数定义函数)