I have a simple node js project, with a server.js file and some dependencies in the node_modules folder. how can i upload the dependencies and the server.js file into lambda function in aws?
Asked
Active
Viewed 490 times
0
-
1You can try using https://www.npmjs.com/package/serverless to deploy. If you don't want to use `serverless` you can refer to this official doc https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html – sagar1025 Jun 30 '20 at 01:47
-
1Does this answer your question? [How to load npm modules in AWS Lambda?](https://stackoverflow.com/questions/34437900/how-to-load-npm-modules-in-aws-lambda) – Kevin Wang Jun 30 '20 at 02:14
1 Answers
2
I'm assuming the server.js file will have a function that will actually be the lambda, which will be called by whatever means you decide in AWS. To do that you can use the serverless framework in your project and create a serverless.yml file.
So let's say you have src folder and the server.js file within. Within that server.js file you have the lamda function. export const myCustomLambda = (event) => { }
. Then on the serverless.yml, in the root directory you do this.
functions:
MyCustomLambda :
handler: src/server.myCustomLambda
With more configuration and after installing the serverless CLI you then deploy it by running serverless deploy
There are more to this, which you can find here in the serverless documentation

Filcp
- 199
- 7
-
1I have also prepared a free course that takes you from "What is Serverless?" to building a multi-service Serverless application: https://www.serverless.com/learn/courses/full-stack-application-development-on-aws/ – Gareth McCumskey Jun 30 '20 at 06:08
-