Jatin Mehrotra
Jatin Mehrotra

Reputation: 11604

How to ignore node_modules with node.js lambda and serverless frameowrk?

I am trying to deploy lambda function using node.js, as of now when i use serverless deploy my entire project directory is being pushed to lambda in a zip file.

But keeping in mind the scale of project, i am looking for something where node_modules are not included when i use serverless deploy and instead they get installed during deployment of lambda, in short something similar to serverless pligins for python https://www.tutorialspoint.com/serverless/serverless_plugins.htm

Upvotes: 0

Views: 2760

Answers (1)

Aaron Stuyvenberg
Aaron Stuyvenberg

Reputation: 3787

The libraries in node_modules are required for your function to run in AWS Lambda. That's why they're called dependencies, and that's why they are zipped and uploaded to S3, because your function needs them in order to run.

If you're using specific libraries like typescript, joi, mocha, or jest which are only meant for development, you can ensure the Serverless framework will not package them by installing them as development dependencies, like this:

npm i -D joi

serverless deploy is the deployment of lambda. The serverless-python-requirements plugin is simply a packaging extension, that gives python projects a similar workflow as nodejs projects with npm.

The only package available to you by Lambda is the aws-sdk

Upvotes: 2

Related Questions