简体   繁体   English

Node.js Lambda-在MySql中使用TypeORM

[英]Node.js Lambda - Using TypeORM with MySql

I'm trying to build some lambda's in node.js and I am using TypeORM with MySql. 我正在尝试在node.js中构建一些lambda,并且我在MySql中使用TypeORM。 I have installed all required node modules but when I deploy lambda (via serverless) and test it, I get errors as follows. 我已经安装了所有必需的节点模块,但是当我部署lambda(通过无服务器)并对其进行测试时,出现以下错误。 Using gulp to build and package .zip. 使用gulp构建和打包.zip。

Log output from test lambda: 测试lambda的日志输出:

START RequestId: 671bed10-81b0-11e7-af34-251688cfdd Version: $LATEST
2017-08-15T11:53:50.594Z    671bed10-81b0-11e7-af34-251688cfdd  
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection 
(rejection id: 2): DriverPackageNotInstalledError: Mysql package has 
not been found installed. Try to install it: npm install mysql --save
2017-08-15T11:53:50.596Z    671bed10-81b0-11e7-af34-251688cfdd  Method:  
"GET"
2017-08-15T11:53:50.596Z    671bed10-81b0-11e7-af34-251688cfdd  Started 
....
2017-08-15T11:53:50.596Z    671bed10-81b0-11e7-af34-251688cfdd  
Finished ....
2017-08-15T11:53:50.596Z    671bed10-81b0-11e7-af34-251688cfdd  
(node:1) PromiseRejectionHandledWarning: Promise rejection was handled 
asynchronously (rejection id: 2)
2017-08-15T11:53:50.597Z    671bed10-81b0-11e7-af34-251688cfddb2    
Console error:  { DriverPackageNotInstalledError: Mysql package has not 
been found installed. Try to install it: npm install mysql --save
at t.Error (native)
at new t (/var/task/index.js:1:48637)
at e.loadDependencies (/var/task/index.js:1:314938)
at new e (/var/task/index.js:1:311241)
at e.createDriver (/var/task/index.js:1:111709)
at e.create (/var/task/index.js:1:104246)
at e.<anonymous> (/var/task/index.js:1:110994)
at r (/var/task/index.js:1:103453)
at Object.next (/var/task/index.js:1:102788)
at /var/task/index.js:1:102697
name: 'DriverPackageNotInstalledError',
message: 'Mysql package has not been found installed. Try to install 
it: npm install mysql --save' }
END RequestId: 671bed10-81b0-11e7-af34-251688cfdd
REPORT RequestId: 671bed10-81b0-11e7-af34-251688cfdd    Duration: 8.71 
ms  Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory 
Used: 39 MB 

My research has led me to believe that it won't package correctly because its a native module. 我的研究使我相信,由于它是本机模块,因此无法正确打包。 But i'm not sure. 但是我不确定。 If so is there anyway to get native node modules to work with lambda's?? 如果有的话,是否有本机节点模块可以与lambda一起使用? Any help would be much appreciated, thanks. 任何帮助将不胜感激,谢谢。


EDIT 编辑

Folder Structure: 资料夹结构:

deploy
-- dev
---- serverless.yml
---- PROJECT.zip
-- test
---- serverless.yml
---- PROJECT.zip
-- prod
---- serverless.yml
---- PROJECT.zip

node_modules
-- *
---- *

src
-- api
---- User
------ index.ts
-- data
---- User.ts
-- models
---- User.ts

gulpfile.js
index.ts
package.json
tsconfig.json
tslint.json

Gulp file calls a function from aws-lambda-typescript module that has numerous gulp tasks. Gulp文件从aws-lambda-typescript模块调用一个具有大量gulp任务的函数。

const gulp = require('gulp');
const awsLambdaTypescript = require('aws-lambda-typescript');

awsLambdaTypescript.registerBuildGulpTasks(gulp, __dirname);

Gulp packages .zip in a dist folder and then i copy to deploy>dev and then serverless deploy. Gulp将.zip打包到dist文件夹中,然后我复制到deploy> dev,然后进行无服务器部署。

Thanks for your help! 谢谢你的帮助!

Most likely something is wrong with your packaging process. 您的包装过程很可能有问题。 I'd check the following items: 我会检查以下项目:

  1. Check your package.json if mysql is there. 检查您的package.json是否有mysql
  2. Check the zip file inside your .serverless directory to see if it includes your node_modules. 检查.serverless目录中的zip文件,以查看其中是否包含node_modules。
  3. Download the lambda package that you uploaded and again check if node_modules are there. 下载您上传的lambda软件包,然后再次检查node_modules是否存在。

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

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