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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

According 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