Function works in Netlify Dev but doesn't work when deployed

Site Name: lunacafe.netlify.app

Function: category.js

x-nf-request-id: de3ed2fd-aaf5-4d57-830f-e8ba0fd5e514-527389

Details:

This function makes a request to an external api. It uses the API’s node client to make the request. When running in netlify dev the function works great and returns in less than a second for first request and 19ms ish for cached requests.

When deployed the function times out and this is the log message:
3:06:56 PM: 2020-08-25T20:06:56.330Z 08f190b8-edf4-4bf2-9895-1821fbcf8ec4 Task timed out after 10.01 seconds

Hey @markgarrigan! :wave:t2:
Welcome to The Community :slight_smile:

Looks like you’re using the async function style for Lambda Handlers but still calling a callback function - sort of mixing the two styles of Lambda functions: async or sync. From your code, it looks like your intention is to use the sync version, so I’d just remove the async tag and you should be better off!

Hope that helps!


Jon

1 Like

Thanks @jonsully!

So then, it’s probably just a race issue between dev and prod? The reason why it works in netlify dev and not on the deployed site?

I tend to think of dev as a replication of AWS Lambda and not always perfect, but generally does the job very well. Since the runtime code isn’t the exact same (AFAIK), we’re bound to find little inconsistencies on fringe cases. These typically come out in instances like this - where the function code itself may have an issue

Also… Could I just change that callback function to instead just return the response object?

Meaning… remove the callback and in place have

return {
  statusCode: 200,
  body: JSON.stringify({})
}
1 Like

Totally. I personally run all of my Functions as async with direct-return rather than sync with callback, but that’s just a general Lambda premise. AWS docs (IMO) are generally difficult to parse through, but if you need reference, this ought to help!

Otherwise, most the Functions examples in Netlify (IIRC) are written as async & direct return, so those can serve as a good example

Yep! That’s exactly on the money

Yeah… I think I just mixed them up at some point and never realized I didn’t change to a direct return cause it was “working” in dev.

Thanks for finding it!!

1 Like

You bet! Let us know if you have any other trouble!