简体   繁体   中英

How do I tell lambda about all the npm dependencies?

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.

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.

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.

In addition to other users who basically gave you the correct answer, I'd suggest trying out Claudia.js, which is a deployment tool for AWS Lambda (at least when used with Node.js).

Using Claudia, you neither have to set up things in the AWS UI, nor do have to worry about packaging stuff. The only downside is that the package that Claudia creates is larger than a hand-built package of the same code, but I'd say this is a neglectable issue given its advantages.

See https://claudiajs.com/ for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM