【发布时间】:2018-04-08 05:26:03
【问题描述】:
我正在尝试在 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());
};
【问题讨论】:
-
嘿,这条线
callback(null, token.toJwt());? mh 不是你如何称呼generateToken的重要部分吗? -
@RolandStarke 这是一个重要的部分,因为这里应该返回结果,我做了另外两个 lambda 函数并且它们运行良好,但是在这里我不断收到我上面写的错误。
-
嗯,AWS Lambda 是否要求您拥有 3 个参数?来自docs
exports.myHandler = function(event, context, callback) { -
@RolandStarke 不,不一定是三个参数
-
我的意思是如果你想使用回调,你需要使用 3 个参数。 (但是是的,ofc 参数名称可能有一些魔力。但一般来说,javascript 中没有命名参数,所以我会尝试用 3 个参数定义你的函数)
标签: node.js aws-lambda twilio