I'm trying to send notification's using FCM & serverless framework, making an HTTP POST request using API Gateway of AWS. The notification to the respective users are getting delivered but receiving below response from AWS with status code 502-Bad Gateway
{
"message": "Internal server error"
}
Here is the code for the aws lambda function
'use strict';
const _ = require('lodash');
const bodyParser = require('body-parser');
const {sendFCMmany, sendFCMone} = require('./tools/sendFCM');
const {sliceData} = require('./tools/splitData');
const students = require('./tools/students');
module.exports.sendNotification = (event, context, callback) => {
var reqBody = JSON.parse(event.body);
var catag = 'announcement';
// For Class
if(reqBody.class_id != "" && reqBody.subclass_id == ""){
var type = 'class';
sendStudent(reqBody,type,catag);
}
// For Section
if(reqBody.class_id != "" && reqBody.subclass_id != ""){
var type = 'section';
sendStudent(reqBody,type,catag);
}
// For Institute
if(reqBody.class_id == "" && reqBody.subclass_id == ""){
var type = 'Institute';
sendStudent(reqBody,type,catag);
}
const response = {
statusCode: 200,
isBase64Encoded: false,
headers: {
"Content-Type": "*/*"
},
body: JSON.stringify({
message: 'Announcement Sent'
}),
};
//console.log(response);
callback(null, response);
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
//callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};
//-------------------------------------------- HELPER FUNCTIONS -------------------------------------------------
function sendStudent(body,type,catag) {
students.getStudents(body,type,catag,(err,student) => {
if(err){
console.log(err);
}
else {
var slicedFCM = sliceData(student,950);
_.forEach(slicedFCM, function(value) {
sendFCMmany(value,body,catag);
});
}
});
}
Actually I'm not able to track the reason for "Internal Server error" how to rectify the same?