For study purposes, I was trying to deploy a nodejs application to lambda, and I found most people did so using the serverless framework.
If we had to do without any such frameworks, or third party tools, how would we do it? I linked my project from s3 after creating the lambda function, and wrote the handler as such:
import cors from 'cors';
import helmet from 'helmet';
import express from 'express';
import bodyParser from 'body-parser';
import routes from './src/routes/routes';
// @ts-ignore
const port = 80;
const app = express();
app.use(helmet());
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/api', routes);
exports.handler = async (_event:any) => {
app.listen(port, () => console.log(`Server started at port: ${port}`));
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
export default app;
and I definitely got a permission denied error. I was trying to make the server run with it exposing the port of the public url endpoint given for the function. Is it possible to do that?