You cannot load NPM modules without uploading a
.zip file, but you can actually get this process down to two quick command lines.
Put your Lambda function file(s) in a separate directory. This is because you install
npmpackages locally for Lambda and you want to be able to isolate and test what you will upload to Lambda.
Install your NPM packages locally with
npm install packageNamewhile you’re in your separate Lambda directory you created in step #1.
Make sure your function works when running locally:
node lambdaFunc.js(you can simply comment out the two
export.handlerlines in your code to adapt your code to run with Node locally).
Go to the Lambda’s directory and compress the contents, make sure not to include the directory itself.
zip -r lambdaFunc.zip .
If you have the
aws-cliinstalled, which I suggest having if you want to make your life easier, you can now enter this command:
aws lambda update-function-code --function-name lambdaFunc \ --zip-file fileb://~/path/to/your/lambdaFunc.zip
(no quotes around the lambdaFunc part above in case you wonder as I did)
Now you can click test in the Lambda console.
I suggest adding a short alias for both of the above commands. Here’s what I have in mine for the much longer Lambda update command:
alias up="aws lambda update-function-code --function-name lambdaFunc \ --zip-file fileb://~/path/to/your/lambdaFunc.zip"