# Functions error decoding lambda response: invalid status code returned from lambda: 0

**URL:** <https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861>\
**Category:** Support\
**Tags:** lambda-functions\
**Created:** [March 22, 2022, 10:01pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861 "2022-03-22T22:01:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Malcolm](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/malcolm/32/62740_2.png) [@Malcolm](https://answers.netlify.com/u/Malcolm)\
**Post date:** [March 22, 2022, 10:01pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861/1 "2022-03-22T22:01:31Z")

</div>

Hi folks, there are a few other posts that mention similar issues, but having tried numerous variations of solutions, I still can’t get this working.

I am calling a Netlify function via POST from a separate AWS Lambda function (not part of my Netlify project). When I run `netlify dev` locally and route my POST to my local dev server via `ngrok`, things work as expected: my Netlify function receives the POST request, and it returns to the aws lambda function without issue.

However, when I deploy to Netlify and do the same thing: 1) My Netlify function receives the POST request without error (as verified via function logs), but 2) My aws lambda function receives a response of `error decoding lambda response: invalid status code returned from lambda: 0` from my Netlify function.

I would very much appreciate help resolving this!

Here is the function code in its present form (though I’ve tried numerous variations of return values based on other forum questions to no avail):

(fwiw current endpoint of this function is [https://boring-varahamihira-cc7a90.netlify.app/.netlify/functions/completedTranscriptionCallback](https://boring-varahamihira-cc7a90.netlify.app/.netlify/functions/completedTranscriptionCallback) ):

```auto
exports.handler = (event, context) => {
  console.log('completedTranscriptionCallback');
  console.log(event);
  console.log(context);

  let responseBody = {
    message: "Body test",
    input: "An input!"
  };

  let response = {
    statusCode: 200,
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(responseBody)
  };
  console.log("response: ", JSON.stringify(response))

  return response;
}

```

As mentioned, if I route this to my local dev environment via e.g. `ngrok` my aws lambda function is able to call it without error and receives the proper response body. It’s only once I deploy to Netlify that the error is returned and logged in lambda.

Thanks! Happy to provide additional info as needed.

---

<div class="post-metadata">

**Author:** ![coelmay](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/coelmay/32/24427_2.png) [@coelmay](https://answers.netlify.com/u/coelmay)\
**Post date:** [March 22, 2022, 10:31pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861/2 "2022-03-22T22:31:37Z")

</div>

Hey @Malcolm

Try changing

```javascript
exports.handler = (event, context) => {
  // code...
}

```

to

```javascript
exports.handler = async (event, context) => {
  // code...
}

```

Check out the first two examples on [this page](https://functions.netlify.com/playground/) for more details on why you need `async`.

---

<div class="post-metadata">

**Author:** ![Malcolm](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/malcolm/32/62740_2.png) [@Malcolm](https://answers.netlify.com/u/Malcolm)\
**Post date:** [March 22, 2022, 10:48pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861/3 "2022-03-22T22:48:22Z")

</div>

Hey @coelmay thanks! That indeed resolved the issue.

Despite spending some time in the docs (today and in the past) I’m still a bit confused regarding the `async` keyword in this context. According to [this page](https://docs.netlify.com/functions/build-with-javascript/#synchronous-function-format) It appears that we’re always supposed to use `async` promise syntax for synchronous Netlify functions? Is that correct?

Is there ever a time we should _not_ use `exports.handler = async (event, context)` in Netlify functions? Or is it essentially a required syntax for _synchronous_ functions? (which was also throwing me a bit, since we’re using `async` in a synchronous function call… Although this appears consistent with the aws lambda docs as well, which I know is what’s running here under-the-hood)

Thanks again for the quick fix!

---

<div class="post-metadata">

**Author:** ![coelmay](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/coelmay/32/24427_2.png) [@coelmay](https://answers.netlify.com/u/coelmay)\
**Post date:** [March 22, 2022, 11:10pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861/4 "2022-03-22T23:10:32Z")

</div>

> [@Malcolm](#):
>
> Is there ever a time we should _not_ use `exports.handler = async (event, context)` in Netlify functions?

When you use a `callback` (as per playground link above.)

```javascript
exports.handler = function (event, context, callback) {
  callback(null, {
    statusCode: 200,
    body: "Hello, World",
  });
};

```

That’s the simple explanation. There are others in these forums, and across the Interwebs who could give a fair more detailed explanation than I. Try `callback vs async` using your preferred search engine 🙂

---

<div class="post-metadata">

**Author:** ![Malcolm](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/malcolm/32/62740_2.png) [@Malcolm](https://answers.netlify.com/u/Malcolm)\
**Post date:** [March 23, 2022, 4:28pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861/5 "2022-03-23T16:28:59Z")

</div>

Actually I do have one followup question: do you know why the incorrect (no `async`) code runs fine when testing locally, and only fails once I push to Netlify?

---

<div class="post-metadata">

**Author:** ![coelmay](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/coelmay/32/24427_2.png) [@coelmay](https://answers.netlify.com/u/coelmay)\
**Post date:** [March 23, 2022, 8:36pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861/6 "2022-03-23T20:36:22Z")

</div>

This I cannot. Perhaps a bug?

> **[Issues · netlify/cli](https://github.com/netlify/cli/issues)**
>
> Netlify Command Line Interface. Contribute to netlify/cli development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Malcolm](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/malcolm/32/62740_2.png) [@Malcolm](https://answers.netlify.com/u/Malcolm)\
**Post date:** [March 28, 2022, 4:19pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861/7 "2022-03-28T16:19:33Z")

</div>

Yup here’s at least one similar version of it from two years ago: [Function response should have empty body if async keyword is missing · Issue #1047 · netlify/cli · GitHub](https://github.com/netlify/cli/issues/1047)

---

<div class="post-metadata">

**Author:** ![coelmay](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/coelmay/32/24427_2.png) [@coelmay](https://answers.netlify.com/u/coelmay)\
**Post date:** [March 28, 2022, 8:30pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861/9 "2022-03-28T20:30:53Z")

</div>

By all means, add your voice to the issue, link back to this thread too for cross-reference.

---

<div class="post-metadata">

**Author:** ![hillary](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hillary/32/21132_2.png) [@hillary](https://answers.netlify.com/u/hillary)\
**Post date:** [March 29, 2022, 5:19pm UTC](https://answers.netlify.com/t/functions-error-decoding-lambda-response-invalid-status-code-returned-from-lambda-0/53861/10 "2022-03-29T17:19:43Z")

</div>

Thanks so much for adding your experience to the issue, @Malcolm. We appreciate it!
