Ich habe eine Lambda-Funktion, die ein Knotenpaket mit gemeinsamen Funktionen importiert. Lambda 1 setzt Meldungen in SQS, Lambda 2 protokolliert Fehler. Eine der gemeinsamen Funktionen ruft Lambda 2 auf, aber es gibt einen Fehler bei diesem zweiten Aufruf.Rufen Sie ein Lambda aus einer Knotenpaketfunktion
Lambda 1:
exports.handler = function (event, context) {
var pnmacCommon = require('./pnmacCommon.js'); //loading node package
try {
// this part omitted for space
var aws = require('aws-sdk');
var sqs = new aws.SQS({ region : 'us-west-2' });
var params = {
MessageBody: JSON.stringify(event),
QueueUrl: '[url]'
};
sqs.sendMessage(params, function(err,data){
if(err) {
console.log('error:',"FAIL Send Message: " + err);
context.done(err, "ERROR Put SQS"); // ERROR with message
pnmacCommon.SvtLogErrorToElmah(application, "FAIL Send Message: " + err, context);
}else{
console.log('Message Sent:', queueUrl);
console.log('data:',data.MessageId);
context.done(null,''); // SUCCESS
}
}
});
}
catch (error) {
pnmacCommon.SvtLogErrorToElmah(application, 'SVTMessageBus_Client' + error, context);
context.done(error, "ERROR put SQS");
}
pnmacCommon.js:
var SvtLogErrorToElmah = function (application, error, context) {
console.log("SvtLogErrorToElmah=" + JSON.stringify(error, null, 2));
// this part omitted for space
var aws = require('aws-sdk');
var lambda = new aws.Lambda({region: 'us-west-2' });
lambda.invoke({
FunctionName: "SVTExceptionLogger",
Payload: JSON.stringify(message, null, 2)
}, function (error2, data) {
if (error2) {
context.fail(error2);
} else {
context.fail(error);
});
context.done(null, message);
}
module.exports.SvtLogErrorToElmah = SvtLogErrorToElmah;
in Cloudwatch sucht, kann ich sehen, dass die SvtLogErrorToElmah
Funktion aufgerufen wird, aber es funktioniert nicht, wenn es die zweite Lambda aufzurufen versucht . Die Fehlermeldung lautet TypeError: lambda.invoke is not a function
.
Irgendwelche Ideen? Vielen Dank im Voraus.