# Error decoding lambda response

**URL:** <https://answers.netlify.com/t/error-decoding-lambda-response/16348>\
**Category:** Support\
**Tags:** lambda-functions\
**Created:** [June 6, 2020, 7:46am UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348 "2020-06-06T07:46:33Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![FollowJack](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/followjack/32/11811_2.png) [@FollowJack](https://answers.netlify.com/u/FollowJack)\
**Post date:** [June 6, 2020, 7:46am UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/1 "2020-06-06T07:46:33Z")

</div>

PLEASE help us help you by writing a good post!

**Site Name:** [https://5edb48143846e0b608a234a0--heuristic-yonath-e84bf6.netlify.app/](https://5edb48143846e0b608a234a0--heuristic-yonath-e84bf6.netlify.app/)  
**DNS issues?** Seems not to be a DNS issue since the live preview already not working. But here anyway the link to my custom domain: [https://www.wiegandautomobile.de/](https://www.wiegandautomobile.de/)  
**Build problems?** Build goes through. Site is live. Cannot see any error.

The message appears whenever calling the site.

error decoding lambda response: error decoding lambda response: json: cannot unmarshal number into Go struct field APIGatewayProxyResponse.multiValueHeaders of type string

The page was running smothly the last 7 days with no issues and changes made. Now one of a sudden, this message appears yesterday night.

The page is a React Next.js application.

Please help. It is live already. My customers getting angry ☹

---

<div class="post-metadata">

**Author:** ![emke](https://avatars.discourse-cdn.com/v4/letter/e/ed8c4c/32.png) [@emke](https://answers.netlify.com/u/emke)\
**Post date:** [June 8, 2020, 8:49am UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/2 "2020-06-08T08:49:03Z")

</div>

Same here, also with an Next.js application. Didn’t made any changes and now getting the same error. Seem especially happing with server side rendered pages which receives data from the api. Pages without data connection are working well. On localhost everything works well.

---

<div class="post-metadata">

**Author:** ![wmclaxton](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/wmclaxton/32/40541_2.png) [@wmclaxton](https://answers.netlify.com/u/wmclaxton)\
**Post date:** [June 8, 2020, 12:51pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/3 "2020-06-08T12:51:51Z")

</div>

We are facing the same error last 2 days. I noticed other posts in this forum facing the same issue in the past 2 days.

- [502 cannot unmarshal number into Go struct field APIGatewayProxyResponse.multiValueHeaders](https://answers.netlify.com/t/502-cannot-unmarshal-number-into-go-struct-field-apigatewayproxyresponse-multivalueheaders/16350)

- [502 error decoding lambda response: error decoding lambda response: json: cannot unmarshal number into Go struct field APIGatewayProxyResponse.multiValueHeaders of type string](https://answers.netlify.com/t/502-error-decoding-lambda-response-error-decoding-lambda-response-json-cannot-unmarshal-number-into-go-struct-field-apigatewayproxyresponse-multivalueheaders-of-type-string/16413)

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [June 8, 2020, 6:21pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/4 "2020-06-08T18:21:57Z")

</div>

These errors are both in how you return values from your lamdba. We did recently add some better support for multivalue headers that might have changed things, but as of today, everything - header, body, etc, needs to be `JSON.stringify()`'d like this:

> <https://github.com/depadiernos/token-hider-inator/blob/master/src/lambda/getapi.js#L21>

When you don’t do that for something that is being returned from your lambda, you’ll receive errors like the above.

---

<div class="post-metadata">

**Author:** ![wmclaxton](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/wmclaxton/32/40541_2.png) [@wmclaxton](https://answers.netlify.com/u/wmclaxton)\
**Post date:** [June 9, 2020, 8:13am UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/5 "2020-06-09T08:13:22Z")

</div>

Not thrilled about the breaking change, but noted, thanks.

---

<div class="post-metadata">

**Author:** ![legionfilms](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/legionfilms/32/11871_2.png) [@legionfilms](https://answers.netlify.com/u/legionfilms)\
**Post date:** [June 9, 2020, 1:17pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/6 "2020-06-09T13:17:25Z")

</div>

It might be worth updating the documentation, as this causes the hello world example in the docs to fail:

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

```

---

<div class="post-metadata">

**Author:** ![perry](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/perry/32/16_2.png) [@perry](https://answers.netlify.com/u/perry)\
**Post date:** [June 9, 2020, 5:38pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/8 "2020-06-09T17:38:41Z")

</div>

hey @legionfilms, thanks for pointing this out. We will take a look!

---

<div class="post-metadata">

**Author:** ![FollowJack](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/followjack/32/11811_2.png) [@FollowJack](https://answers.netlify.com/u/FollowJack)\
**Post date:** [June 13, 2020, 4:56pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/11 "2020-06-13T16:56:27Z")

</div>

To anyone who has a problem with next js on netlify: [API route not passing query string · Issue #9 · netlify/next-on-netlify · GitHub](https://github.com/FinnWoelm/next-on-netlify/issues/9#issuecomment-637761007)  
This fixed it for me.

---

<div class="post-metadata">

**Author:** ![Dennis](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dennis/32/34_2.png) [@Dennis](https://answers.netlify.com/u/Dennis)\
**Post date:** [June 15, 2020, 5:50pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/14 "2020-06-15T17:50:11Z")

</div>

Hi @FollowJack, around that time, we did add support for multiValueHeaders in Lambda Function response. That link you mentioned looks to have addressed the change. I’d be interested to hear the experience of the others that reported this issue and if that update mentioned also fixed their issue.

---

<div class="post-metadata">

**Author:** ![jamesqquick](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jamesqquick/32/10337_2.png) [@jamesqquick](https://answers.netlify.com/u/jamesqquick)\
**Post date:** [September 29, 2020, 7:56pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/15 "2020-09-29T19:56:28Z")

</div>

I’m trying to use multiValueHeaders in Netlify function response to set multiple cookies. It works locally with Netlify dev but not when deployed. Any ideas?

---

<div class="post-metadata">

**Author:** ![jamesqquick](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jamesqquick/32/10337_2.png) [@jamesqquick](https://answers.netlify.com/u/jamesqquick)\
**Post date:** [September 29, 2020, 8:01pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/16 "2020-09-29T20:01:59Z")

</div>

I ended up having some values in the multiValueHeaders property that did not have multiple values lol Guess that was a problem. I’m setting multiple cookies like this.

```
return {
        statusCode: 302,
        headers: {
            Location: `${process.env.APP_DOMAIN}`,
            'Cache-Control': 'no-cache',
        },
        multiValueHeaders: {
            'Set-Cookie': [netlifyCookie, auth0LoginCookie],
        },
        body: JSON.stringify({ msg: `you're good` }),
    };
```

---

<div class="post-metadata">

**Author:** ![jen](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jen/32/6044_2.png) [@jen](https://answers.netlify.com/u/jen)\
**Post date:** [October 2, 2020, 11:49pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/17 "2020-10-02T23:49:50Z")

</div>

Hey @jamesqquick, thanks for coming back to report your fix!

---

<div class="post-metadata">

**Author:** ![JoseJuan81](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/josejuan81/32/18335_2.png) [@JoseJuan81](https://answers.netlify.com/u/JoseJuan81)\
**Post date:** [November 13, 2020, 3:13am UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/18 "2020-11-13T03:13:03Z")

</div>

Hello,  
I have this problem but I’m using graphql and I need help. Please check the code below

/lambda/graphql.js  
`exports.handler = async function handler(event, context) {  
try {  
await connectToMongoDB();

```
const typeDefs = getTypeDefs(gql);
const resolvers = getResolvers;

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context: () => ({
    models: {
      ExpenseModel,
      TaskModel,
    },
  }),
});

return new Promise((yay, nay) => {
  const cb = (err, args) => (err ? nay(err) : yay(args));
  server.createHandler({
    cors: {
      origin: '*',
    },
  })(event, context, cb);
});

```

} catch (error) {  
console.error(‘Error al conectarse con BD’, error);

```
return false;

```

}  
};`  
How can I apply JSON.stringify?

---

<div class="post-metadata">

**Author:** ![jen](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jen/32/6044_2.png) [@jen](https://answers.netlify.com/u/jen)\
**Post date:** [November 15, 2020, 1:26am UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/19 "2020-11-15T01:26:28Z")

</div>

This code looks very familiar! Which makes me think that you’re seeing the same error as the OP but for a different reason. We worked through something similar over here:

> [@Build Netlify lambda function + Apollo gateway together](https://answers.netlify.com/t/build-netlify-lambda-function-apollo-gateway-together/20374/4):
>
> Hey @peter-wd-1, TL;DR if you just want the working site and repo slight_smile site: [https://naughty-almeida-49c564.netlify.app/](https://naughty-almeida-49c564.netlify.app/) repo: [GitHub - kaganjd/netlify-lambda-apollo-federation: This project sets up boilerplate for `netlify-lambda` functions using `apollo/federation`](https://github.com/kaganjd/netlify-lambda-apollo-federation) commit history so you can look at what I changed in each step: [Commits · kaganjd/netlify-lambda-apollo-federation · GitHub](https://github.com/kaganjd/netlify-lambda-apollo-federation/commits/master) this uses the built-in “zip and ship” functionality as opposed to netlify-lambda, but you sti…

Want to check out that thread and let us know if it helps you resolve the issue?

---

<div class="post-metadata">

**Author:** ![JoseJuan81](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/josejuan81/32/18335_2.png) [@JoseJuan81](https://answers.netlify.com/u/JoseJuan81)\
**Post date:** [November 16, 2020, 8:58pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/20 "2020-11-16T20:58:57Z")

</div>

Hello Jen,  
I have no node\_modules in my lambda folder (like the topic tha you sent me to check). I use just one package.json and it is in the project root.  
Works fine in local but Netlify throws a 502 error. I still need to run `npm i` inside my lambda folder?

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [November 29, 2020, 9:45pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/21 "2020-11-29T21:45:55Z")

</div>

Depends entirely on how you send the function - which of these 3 methods would you be trying to use?

> **[GitHub - netlify/function-deploy-test](https://github.com/netlify/function-deploy-test)**
>
> Contribute to netlify/function-deploy-test development by creating an account on GitHub.

2/3 of them would not require you to do that 🙂

---

<div class="post-metadata">

**Author:** ![JoseJuan81](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/josejuan81/32/18335_2.png) [@JoseJuan81](https://answers.netlify.com/u/JoseJuan81)\
**Post date:** [November 29, 2020, 10:25pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/22 "2020-11-29T22:25:32Z")

</div>

Hello! Thanks for your answer.  
I use the netlify-lambda to build the bundle that I need.

---

<div class="post-metadata">

**Author:** ![deward](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@deward](https://answers.netlify.com/u/deward)\
**Post date:** [November 9, 2024, 1:48pm UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/23 "2024-11-09T13:48:00Z")

</div>

Faced a simmilar issue using `compatibilityDate: "2024-11-09"` in Nuxt `3.10.2`. I just removed it.

---

<div class="post-metadata">

**Author:** ![bastianhilton](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/bastianhilton/32/28628_2.png) [@bastianhilton](https://answers.netlify.com/u/bastianhilton)\
**Post date:** [November 20, 2024, 4:02am UTC](https://answers.netlify.com/t/error-decoding-lambda-response/16348/24 "2024-11-20T04:02:50Z")

</div>

this was my issue as well, thank you
