How do I tell lambda about all the npm dependencies?

183
December 17, 2017, at 4:04 PM

I'm reading this tutorial on how to write a node restful app

https://github.com/mjhea0/node-postgres-promises

I want to run this app as a lambda function. My worry is the dependency management.

How do I tell lambda about all the npm dependencies?

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var pug = require('pug');
var routes = require('./routes/index');

In the tutorial they do npm install and with aws serveless we don't have a concept of cli commands like that.

Answer 1

You do npm install on your local machine (ideally Linux). Then, when you create a deployment package, you will include the node_modules folder in it.

Once you upload that deployment package (zip file), Lambda will be aware of your node_modules and extract them together with your handler.

Answer 2

you can develop your application on the local machine and install all npm dependencies in the project you built (in local machine). Once you are complete development zip all the files (including package.config and npm_modules) and upload it to lambda. Please note while zipping the file

please don't zip the root folder. Open root folder select all files and folders inside that then right click zip all.

READ ALSO
Expressjs: Processing errors from DB operations (next is undefined)

Expressjs: Processing errors from DB operations (next is undefined)

I am trying to develop a flow-pattern to handle errors encountered when trying to perform database operationsI am a little lost, but I think I am pretty close to figuring it out

159
How can aws api gateway listen to 2 lambda functions?

How can aws api gateway listen to 2 lambda functions?

My design is that api will trigger first lambda function, this function then send sns and return, sns triggers second lambda functionNow I want that api get the response from the second lambda function

168
I got a post-install error while updating Node JS with Brew

I got a post-install error while updating Node JS with Brew

I need to ask a question on the matter of updating Node JS with brewFor one, I was able to download the latest version of Node JS via brew, but then, when I typed in (if I assume if my memory is correct) brew install node, I got a post-install error

174
How to list local npm package contents

How to list local npm package contents

I need to list all files that would be included by npm pack command for a local(unpublished) package, but without doing the packing in the first place

321