I have a very basic node.js example running AWS and I need to modify the code to add a dependency on the "request" module.
I have understood that you need to package this up into a zip file with the necessary node module.
I download the index.js and add the code. I create package.json:
{
"name": "function",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"zip": "zip function.zip package.json *.js node_modules"
},
"dependencies": {
"aws-sdk": "^2.4.10",
"request": "^1.0"
}
}
I use npm install to pull in the dependency. This populated the node_modules subfolder with the module and its dependencies.
Then I just zipped this up but the AWS console would not upload it.
This Q&A Creating a lambda function in AWS from zip file told me not to zip normally but to use npm like so: ` npm run zip
> function@1.0.0 zip /Users/paul_tanner/Desktop/index
> zip function.zip package.json *.js node_modules
adding: package.json (deflated 36%)
adding: index.js (deflated 73%)
adding: node_modules/ (stored 0%)`
Before trying to upload and test this I opened it up to check that the dependencies were included. They were not.
Just for the hell of it I also tried uploading the resulting "function.zip". Again, AWS Lambda would not upload it.
So the question is how should one create and upload an AWS Lambda function with dependency?