dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 166 forks source link

Callback is not a function. #40

Closed ajmwagar closed 5 months ago

ajmwagar commented 6 years ago

using

module.exports.handler = serverless(app);

I get the following error:

2018-03-18T06:08:03.347Z - error: /home/ajmwagar/usr/dev/git/outrigger/node_modules/serverless-http/serverless-http.js:58
        callback(e);
        ^

TypeError: callback is not a function
    at process.nextTick (/home/ajmwagar/usr/dev/git/outrigger/node_modules/serverless-http/serverless-http.js:58:9)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
2018-03-18T06:08:03.355Z - info: Execution took 12 ms, finished with status: 'crash'
2018-03-18T06:08:03.374Z - error: Function worker crashed with exit code: 1

I will look into a fix.

Thanks for maintaining such a great library.

ajmwagar commented 6 years ago

After doing more digging. I figured out the actual error I am getting, (to trigger the catch block) is:

2018-03-18T06:19:15.083Z - info: TypeError: Cannot set property path of #<IncomingMessage> which has only a getter
    at cleanupEvent (/home/ajmwagar/usr/dev/git/outrigger/node_modules/serverless-http/lib/clean-up-event.js:7:14)
    at Promise.resolve.then (/home/ajmwagar/usr/dev/git/outrigger/node_modules/serverless-http/serverless-http.js:28:23)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Any ideas?

dougmoscrop commented 6 years ago

I will have a look on Monday! Can you provide versions?

dougmoscrop commented 6 years ago

@ajmwagar can you tell me more about how you are using this library?

these log lines look unfamiliar to me:

2018-03-18T06:08:03.355Z - info: Execution took 12 ms, finished with status: 'crash' 2018-03-18T06:08:03.374Z - error: Function worker crashed with exit code: 1

It looks like the event object has a read-only property on it, which doesn't match how I've seen it work in AWS Lambda, as this is the code causing the exception: https://github.com/dougmoscrop/serverless-http/blob/d668f99580d4f9e35ed769b0a3b31e73f487815d/lib/clean-up-event.js#L7

Are you running this in a different environment? Google Cloud? Some Emulator? I took a guess at how I might support these properties somehow being readonly by using Object.create, you can try it on the object_create branch and let me know, but I'd prefer to understand and ideally reproduce the problem rather than guess at a solution.

ajmwagar commented 6 years ago

I have been using Google Cloud. I that an issue?

However, those logs were from my custom logging setup. (Winston)

dougmoscrop commented 6 years ago

I have never used Google Cloud! Can you try my #object_create branch and let me know if it works?

dougmoscrop commented 6 years ago

Also if you could share what your code looks like I would love to know.

dylan0d commented 5 years ago

@ajmwagar Did you ever manage to fix this? My team is migrating from AWS serverless to google Cloud Functions and running into the same error message

dougmoscrop commented 5 years ago

@dylan0d this library technically doesn't support Google Cloud but I did just refactor it to support different providers (yet to be implemented tho)

The way Google looks it seems like it already does most of what severless-http is. I'm fine adding a shim, but you should really just try passing their req/res objects to the callback/handle/etc method for whichever framework you're using.

Basically for GCP I think you just need to figure out which case it is and use it from here:

https://github.com/dougmoscrop/serverless-http/blob/master/lib/framework/get-framework.js

dylan0d commented 5 years ago

@dougmoscrop Ok I will try that, thank you for your quick response!

dougmoscrop commented 5 years ago

@ajmwagar @dylan0d given that I've got support for multiple providers now, do you have any appetite to contribute GCP support in this library (even if it just defaults to a 'no op' type passthrough, it would be nice if this library was a kind of common shim)