AWS Lambda Invoke does not execute the lambda function

ساخت وبلاگ

Vote count: 0

I created 4 Lambda functions to process information that will be written into a MySQL table. the first three function just select, insert and update a MYSQL table record respectively.

I then created a 4th function to accept the record detail as part of the event parameter. This function will first try to select the record by invoking the first lambda function and if it finds it, will update the record on the table using the update lambda function. If it does not find it, it will invoke the insert function to add the record. I am using pool.query on the 3 functions that manipulates the MySQL table. I am also using lambda.invoke to call those three functions from the 4th function.

I was able to successfully test the 4th function locally by passing the record details as parameter and it was able to successfully call the three Lambda function and update the mySQL table record. The problem that I am having is that when I upload the function in AWS Lambda, it does not invoke any of the three functions. I am not seeing any errors in the log so I don't know how to check where the problem is. Here's ,y code that invokes the other functions:

exports.handler = (event, context, callback) => {
var err = null;
var payload = { qryString : event.qryString, record: event.updaterecord, dbConfigPool : event.dbConfigPool }
var params = { FunctionName: 'getInventory', Payload: JSON.stringify(payload)
}
console.log(' before invoke ' + JSON.stringify(params) )
lambda.invoke(params, function(err, data) {
console.log(' aftr invoke ' + JSON.stringify(params) ) if (err) { console.log('err ' + err, err.stack); // an error occurred event.message = err + ' query error'; } else { console.log('success' + JSON.stringify(data)); console.log(' status code ' + JSON.stringify(data.StatusCode)); console.log(' Payload ' + JSON.stringify(JSON.parse(data.Payload))); var rowsTemp = JSON.parse(data.Payload); var rows = rowsTemp.data; if (!rowsTemp.recordExist) { console.log('insert') // Update inventory record only if quantity is not negative var newQuantity = 0 newQuantity = parseFloat(event.updaterecord.quantity); if (Math.sign(newQuantity) === 1) { var payload = { record: event.updaterecord, dbConfigPool : event.dbConfigPool } console.log('insert' + JSON.stringify(payload)); var params = { FunctionName: 'insertInventory', Payload: JSON.stringify(payload) } lambda.invoke(params, function(err, data) { if (err) console.log(err, err.stack); // an error occurred else console.log(data); // successful response }); } } else { newQuantity = 0 newQuantity = parseFloat(event.updaterecord.quantity) + parseFloat(rows[0].quantity); if (Math.sign(newQuantity) === 1) { event.updaterecord.quantity = newQuantity; } else { // Set to zero if the result is negative event.updaterecord.quantity = 0; } console.log('value ' + JSON.stringify(newQuantity) + ' updaterecord' + JSON.stringify(event.updaterecord.quantity) ); var payload = { qryString : event.qryString, record: event.updaterecord, dbConfigPool : event.dbConfigPool } console.log('update' + JSON.stringify(payload)); var params = { FunctionName: 'updateInventory', Payload: JSON.stringify(payload) } console.log(' before invoke ' + JSON.stringify(params) ) lambda.invoke(params, function(err, data) { console.log(' after invoke ' + JSON.stringify(params) ) if (err) { console.log('err ' + err, err.stack); // an error occurred event.message = err + ' query error'; } else { console.log(data); } // else }); // lambda invoke } } // successful response
});
console.log(' end of function');
var completed = true;
context.callbackWaitsForEmptyEventLoop = false;
callback(null, completed);
}

Apologies if the code is quite long. But I wanted to show that I did put a number of console.logs to monitor where is goes through. The cloudwatch logs only shows the first message before the first lambda.invoke and then it shows the last message for the end of the function.

I am also not seeing any log entris in cloudwatch for the three functions that has been invoked.

asked 3 mins ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 223 تاريخ : چهارشنبه 26 خرداد 1395 ساعت: 14:58