Node.js AWS Lambda TypeError:回调不是函数
我试图在AWS lambda中创建twilio访问令牌,但我得到错误“回调不是函数”。我怎样才能修好它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
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个参数定义函数)