admin管理员组文章数量:1355703
I have deployed a NodeJs server to AWS Lambda and it is being triggered by an API gateway. However, I am getting the following error in my live tail:
Error:
"errorType": "TypeError",
"errorMessage": "server is not a function",
"stack": [
"TypeError: server is not a function",
" at Runtime.handler (file:///var/task/index.js:14:44)",
" at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"
]
}
My index.js
file looks like this:
import express from 'express';
import routes from './startup/routes.js';
import db from './startup/db.js';
import { createServer } from 'aws-serverless-express';
const app = express();
routes(app);
db();
// const port = process.env.PORT || 8080;
// app.listen(port, () => console.log(`Listening on port ${port}...`));
const server = createServer(app);
export const handler = (event, context) => server(event, context);
I am absolutely new to AWS and serverless in NodeJs
I have deployed a NodeJs server to AWS Lambda and it is being triggered by an API gateway. However, I am getting the following error in my live tail:
Error:
"errorType": "TypeError",
"errorMessage": "server is not a function",
"stack": [
"TypeError: server is not a function",
" at Runtime.handler (file:///var/task/index.js:14:44)",
" at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"
]
}
My index.js
file looks like this:
import express from 'express';
import routes from './startup/routes.js';
import db from './startup/db.js';
import { createServer } from 'aws-serverless-express';
const app = express();
routes(app);
db();
// const port = process.env.PORT || 8080;
// app.listen(port, () => console.log(`Listening on port ${port}...`));
const server = createServer(app);
export const handler = (event, context) => server(event, context);
I am absolutely new to AWS and serverless in NodeJs
Share Improve this question edited Mar 30 at 12:21 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 29 at 21:29 Chirag MauryaChirag Maurya 732 silver badges14 bronze badges1 Answer
Reset to default 1According to aws-serverless-express document, you have to use proxy
to handle the event:
// ...
import { createServer, proxy } from 'aws-serverless-express';
// ...
export const handler = (event, context) => { proxy(server, event, context) };
本文标签: nodejsAWS Lambda not reading my serverless function in NodeStack Overflow
版权声明:本文标题:node.js - AWS Lambda not reading my serverless function in Node - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744003247a2574243.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论