nitro
nitro copied to clipboard
Nuxt 3.0.0-rc.9 with Nitro 0.5.0 configuration error: Malformed Lambda proxy response
Environment
Nuxt 3.0.0-rc.9 with Nitro 0.5.0
Reproduction
I build the Nuxt app with aws-lambda deployment setting and configured Amazon API Gateway proxy integration to work with this lambda function. When I call my endpoint, I receive a configuration error and an HTTP 502 status code.
Execution failed due to configuration error: Malformed Lambda proxy response
Describe the bug
As I commented in the PR (https://github.com/unjs/nitro/pull/357#issuecomment-1247562089), this is due to the fact that cookies are returned in the response object.
For API Gateway to handle a Lambda function's response, the function must return output according to the following JSON format. Additional fields are not allowed.
{
"isBase64Encoded": true|false,
"statusCode": httpStatusCode,
"headers": { "headerName": "headerValue", ... },
"body": "..."
}
cf. https://aws.amazon.com/premiumsupport/knowledge-center/malformed-502-api-gateway/?nc1=h_ls
Additional context
Related Issues and PRs are as follows.
- https://github.com/unjs/nitro/pull/357
- https://github.com/unjs/nitro/issues/245
Logs
No response
@danielroe At this point, is there any other way than to create a wrapper for the handler (index.mjs) ourselves?
Yes, Nitro presets are fully extensible. Copy this file into your project, make the necessary changes, and set nitro.entry
to point to your changed file...
(Of course, we do plan to fix the issue in Nitro itself!)
Thank you for your prompt response. I will try the approach you suggested.
@datake914 (and others affected): sorry about the push for the change in #357 -- the separate cookies
property is required if you are using Cloudfront vs. API Gateway.
Yes, Nitro presets are fully extensible. Copy this file into your project, make the necessary changes, and set
nitro.entry
to point to your changed file...(Of course, we do plan to fix the issue in Nitro itself!)
This solution doesn't seem to work with current version of nuxt, any suggestion on how to do this?
@timmak I am using Nuxt 3.0.0-rc.11 with Nitro 0.5.4 and it works fine.
I specify in nuxt.config.ts
to use custom nitro.entry.ts
only when process.env.NODE_ENV
is production.
nitro: {
preset: 'aws-lambda',
serveStatic: false,
entry: process.env.NODE_ENV === 'production' ? 'nitro.entry.ts' : undefined,
},
@datake914 Maybe what I am missing is where to import nitroApp
from in nitro.entry.ts
, as currently it not outputting similar output as without the entry file