Error decoding lambda response

PLEASE help us help you by writing a good post!

Site Name: 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/
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 :frowning:

2 Likes

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.

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.

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:

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

3 Likes

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

1 Like

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

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

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

To anyone who has a problem with next js on netlify: API route not passing query string Ā· Issue #9 Ā· netlify/next-on-netlify Ā· GitHub
This fixed it for me.

1 Like

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.

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?

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` }),
    };
2 Likes

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

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?

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:

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

1 Like

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?

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

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

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

1 Like

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

1 Like

this was my issue as well, thank you