Lambda Serverless Nodejs - Getting "Internal server error" when callback is called inside a promise

Abhinav Juneja

I am trying to call the callback(null,response) inside .then() block of a promise. It works fine when i am using serverless offline but its giving error when using serverless.

There are two scenarios:

1 Works fine (when deployed using serverless deploy and when using sls offline start)

module.exports.getAssembly = (event, context, callback) => {

        const response = {
            statusCode: 200,
            body: JSON.stringify({
                message: 'Go Serverless v1.0! Your function executed successfully!'
            }),
        };
        callback(null, response)


}

2 Works fine with sls offline but gives internal server error with serverless deploy

module.exports.getAssembly = (event, context, callback) => {


    mysql.query('SELECT * from assemblies',connection).then((returnedObject)=>{
        const response = {
            statusCode: 200,
            body: JSON.stringify({
                message: returnedObject.results
            }),
        };
        callback(null, response)

    })

}

There is some problem with the callback(null,response) inside the .then() block of the promise

Abhinav Juneja

Setting context.callbackWaitsForEmptyEventLoop = false; solves the problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Using service key for SpreadsheetService authentication and getting Internal Server Error when trying to get the feed

Getting 500 INTERNAL SERVER ERROR when unittesting a (flask-restful) GET API Call

NodeJS Update API - Internal Server Error

Getting Internal Server Error when sending POST request with an image file to database using React JS and Laravel

AWS - Serverless - "message": "Internal server error" when deploying, but work offline

Bot published to Azure getting Internal Server Error

AJAX request works fine but when I click the icon that is inside the button, I get a 500 internal server error

Getting internal server error when posting to my website, but not when deleting posts

AWS Lambda returning internal server error for no reason

Getting a 500 Internal Server Error when rewriting 2 specific URLs

Internal server error - when upload base64 through aws lambda/api gateway/s3

When Publish sample project of .net core web app in IIS getting HTTP Error 500.19 Internal Server Error

getting 500 internal server error?

Getting 500 internal server error when passing Json to MVC controller

Getting a 500 internal server error for wordpress site?

Getting Internal Server Error when trying to use Gviz's IdeogramTrack

Getting an error 500 internal server error

Why am I getting an internal server error when deploying Django with Heroku (admin page still works)?

502 "Internal Server Error" with API Gateway + Lambda when deploying

AWS Lambda calling API gateway getting 500 internal server error

Always getting back an, "Internal Server Error," when trying to run ban command on my Discord bot

"internal server error" with API gateway and lambda on AWS

Why am I getting Internal Server Error when I'm using Flask?

internal server error with when deploying express with serverless

Internal Server Error from AWS lambda in python when returning empty body

Javascript Promise Callback (when it is called)

Getting 500 Internal Server Error when calling /mint_nft NEAR REST API

Getting 500 Internal Server Error SpringBoot

"Internal Server Error" when querying of DynamoDB in Lambda using Python

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive