I’m using bluebird Promise in my handler method. The function returns successfully when I invoke on local but time out when running on Lambda. The callback methods on local and lambda seem to be different too.
I can see the result of my method on lambda log. However when I call callback(null, response) nothing seems to happened. It just stuck there and time out.
Are you setting a specific timeout value? Do you have logging to see what it’s (stuck?) doing when it times-out? Without knowing what kind of work your function is doing and what timeout value you’ve set, there’s no way for us to know if you’re not getting a legitimate timeout in Lambda…
What do you mean by:
exactly? What calls? How are they different?
The only other thing I can think of is to check when/if you’re returning your callback() calls, as that sometimes can result in different end-states in the Lambda environment vs locally.
No I didn’t set specific timeout value from code.
My function queries my db and returns result. I can see the result from my query already, but it stuck at this line
return callback(null, response)
The callback functions in the signature. When I invoke locally, the body of that method is the body of callback you can find in invokeLocalNodeJs(handlerPath, handlerName, event) in lib/plugins/aws/invokeLocal/index.js, while body of that method when running on Lambda is
I did `return callback(null, response)``` from the promise.
On a side note, when I invoke locally, after I see my result, it takes about 40s until it completely stop.
After raising the timeout to 40s, I can get successful result from Lambda and got charged for 30s. My query is very fast, should complete under 1s. Is there something I need to pay attention to here?
Cool, I didn’t know about the differences in the payload.
+1 to @buggy’s suggestion to use native Promises; That’s what I use, and haven’t had any issue.
Do you have any logging or instrumentation that tells you where the function is spending all of its time in Lambda? i.e. if the query should be finished in <1 second, can you see if that is happening when run in Lambda?