AWS Lambda TypeError:回调不是函数

时间:2018-03-30 17:03:14

标签: 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 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());
    };

1 个答案:

答案 0 :(得分:0)

正如Roland Starke所说,值得将此exports.generateToken = function(identity, callback)更改为exports.generateToken = function(event, context, callback),一切都会正常。