简体   繁体   English

如何将所有npm依赖项告诉lambda?

[英]How do I tell lambda about all the npm dependencies?

I'm reading this tutorial on how to write a node restful app 我正在阅读有关如何编写Node Restful App的教程

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

I want to run this app as a lambda function. 我想将此应用程序作为lambda函数运行。 My worry is the dependency management. 我担心的是依赖管理。

How do I tell lambda about all the npm dependencies? 如何将所有npm依赖项告诉lambda?

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. 在本教程中,他们进行npm install ,而aws则无用,我们没有cli命令这样的概念。

you can develop your application on the local machine and install all npm dependencies in the project you built (in local machine). 您可以在本地计算机上开发应用程序,并将所有npm依赖项安装在您构建的项目中(在本地计算机中)。 Once you are complete development zip all the files (including package.config and npm_modules) and upload it to lambda. 完成开发后,请压缩所有文件(包括package.config和npm_modules),然后将其上传到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. 打开根文件夹,选择其中的所有文件和文件夹,然后右键单击全部zip。

You do npm install on your local machine (ideally Linux). 您在本地计算机(最好是Linux)上进行npm install Then, when you create a deployment package, you will include the node_modules folder in it. 然后,在创建部署程序包时,将在其中包含node_modules文件夹。

Once you upload that deployment package (zip file), Lambda will be aware of your node_modules and extract them together with your handler. 一旦上传了该部署程序包(zip文件),Lambda就会知道您的node_modules并将其与您的处理程序一起提取。

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). 除了基本上为您提供正确答案的其他用户外,我建议您试用Claudia.js,它是AWS Lambda的部署工具(至少与Node.js结合使用时)。

Using Claudia, you neither have to set up things in the AWS UI, nor do have to worry about packaging stuff. 使用Claudia,您不必在AWS UI中进行设置,也不必担心打包内容。 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. 唯一的缺点是Claudia创建的程序包比具有相同代码的手工构建的程序包要大,但是鉴于其优势,我想说这是一个可以忽略的问题。

See https://claudiajs.com/ for more info. 有关更多信息,请参见https://claudiajs.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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