claudiajs / claudia

Deploy Node.js projects to AWS Lambda and API Gateway easily
https://claudiajs.com
MIT License
3.8k stars 276 forks source link

Promises/Await Issue with 3rd Party Library (Shopify) #153

Closed josephchan91 closed 6 years ago

josephchan91 commented 6 years ago

I'm using lambda to implement a small utility app that interacts with Shopify using this package. However, calling a promise-returning method of the library seems to cut short the execution of the function. It worked fine before I migrated it from Webtask and when testing locally. The code within my express function looks like this:

// function runs until here
const order = await shopify.order.get(orderId);
// but doesn't make it to this point

These are the error logs I'm getting:

CloudWatch log: {"message": "Internal server error"}

API Gateway log: Execution failed due to configuration error: Malformed Lambda proxy response

Does anyone know what could possibly be going on? I've trying the statement in a try/catch but am not getting any errors from CloudWatch either.

gojko commented 6 years ago

As you're using the express wrapper, this is a problem with aws-serverless-express, not with claudia, so it's best to ask there (https://github.com/awslabs/aws-serverless-express).

If you're building an API instead of a web site, I suggest using the claudia-api-builder, that supports promises returning from handlers nicely, so you just need to return the promise out in order for it to wait for execution (but make sure you're running the lambda with node8.10, earlier versions do not support awaits)