title: 502 Bad Gateway Internal Server error
body: <p>I'm trying to send notification's using FCM &amp; 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</p>
  
  <pre><code>{
      "message": "Internal server error"
  }
  </code></pre>
  
  <p>Here is the code for the aws lambda function </p>
  
  <pre><code>'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) =&gt; {
  
      var reqBody = JSON.parse(event.body);
  
      var catag = 'announcement';
  
      // For Class
      if(reqBody.class_id != "" &amp;&amp; reqBody.subclass_id == ""){
          var type = 'class';
          sendStudent(reqBody,type,catag);
      }
  
      // For Section
      if(reqBody.class_id != "" &amp;&amp; reqBody.subclass_id != ""){
          var type = 'section';
          sendStudent(reqBody,type,catag);
      }
  
      // For Institute
      if(reqBody.class_id == "" &amp;&amp; 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) =&gt; {
          if(err){
             console.log(err);
          }
          else {
  
              var slicedFCM = sliceData(student,950);
  
              _.forEach(slicedFCM, function(value) {
                  sendFCMmany(value,body,catag);
              });
          }
      });
  }
  </code></pre>
  
  <p>Actually I'm not able to track the reason for "Internal Server error" how to rectify the same?</p>