I have a standard (hello-world) package.json for my aws lambda app:
{
"name": "hello_world",
"version": "1.0.0",
"description": "hello world sample for NodeJS",
"main": "app.js",
"repository": "https://github.com/awslabs/aws-sam-cli/tree/develop/samcli/local/init/templates/cookiecutter-aws-sam-hello-nodejs",
"author": "SAM CLI",
"license": "MIT",
"dependencies": {
"axios": "^0.21.1"
},
"scripts": {
"test": "mocha tests/unit/"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.2.1"
}
}
However if I run npm i, it creates node_modules folder within this hello-world folder which is deployed to AWS lambda when I run sam deploy.
It is not needed because I keep all necessary dependencies in a separate layer. However if I delete them, then I can't test locally (sam local start-api) because the app raises an exception since it can't find the dependencies. What should I do to avoid node_modules to be deployed to AWS but still have a possibility to run it locally?