Claudia.js create在打字稿项目中找不到模块lambda

时间:2018-08-13 14:13:59

标签: amazon-web-services typescript aws-lambda claudiajs claudia.js

搜索了几个小时之后,我不知道如何在项目中正确运行 claudia create

this turoial之后,我创建了一个组和一个用户AWS控制台,然后将密钥添加到了我的 .aws / credentials 文件中。

然后我运行了正确生成lambda.js文件的命令:

  

claudia --source dist generate-serverless-express-proxy --express-module应用

我的 lambda.js

'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const binaryMimeTypes = [
    'application/octet-stream',
    'font/eot',
    'font/opentype',
    'font/otf',
    'image/jpeg',
    'image/png',
    'image/svg+xml'
]
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)

然后,我尝试在AWS上部署lambda函数:

  

claudia create --source dist --profile myprofile --handler lambda.handler --deploy-proxy-api --region eu-west-1

但是我得到了这个错误:

  

验证包TypeError:“ listener”参数必须是一个函数       在_addListener(events.js:239:11)       在Server.addListener(events.js:297:10)       在新服务器上(_http_server.js:269:10)       在Object.createServer(http.js:34:10)       在Object.createServer(/tmp/IiRPif/my-project-1.0.0-1Yh6Wb/package/node_modules/aws-serverless-express/index.js:155:25)       在对象。 (/tmp/IiRPif/my-project-1.0.0-1Yh6Wb/package/lambda.js:13:37)       在Module._compile(module.js:652:30)       在Object.Module._extensions..js(module.js:663:10)       在Module.load(module.js:565:32)       在tryModuleLoad(module.js:505:12)       在Function.Module._load(module.js:497:3)       在Module.require(module.js:596:17)       在要求时(internal / module.js:11:18)       在validatePackage(/usr/local/lib/node_modules/claudia/src/tasks/validate-package.js:16:15)       在initEnvVarsFromOptions.then.then.then.then.then.then.then.dir(/usr/local/lib/node_modules/claudia/src/commands/create.js:342:10)       全新安装后,在不需要./lambda。检查您的依赖性。

我在这里做什么错了?

我的 package.json

{ 
  "name": "...",
  "version": "1.0.0",
  "scripts": {
    "build": "tsc -p tsconfig.json & cp \"package.json\" \"dist/package.json\"
  },
  "repository": {
    "type": "git",
    "url": "..."
  },
  "homepage": "...",
  "dependencies": {
    "body-parser": "^1.18.3",
    "express": "^4.16.3",
    "mongoose": "^5.2.7",
    "nodemon": "^1.18.3"
  },
  "devDependencies": {
    "typescript": "^3.0.1"
  }
}

我的 app.ts

import * as express from "express";
import * as bodyParser from "body-parser";
import * as mongoose from "mongoose";
import { Routes } from "./routes/routes";

class App {

    public app: express.Application;
    public routes: Routes = new Routes();

    constructor() {
        this.app = express();

        // Parser setup
        this.app.use(bodyParser.json());
        this.app.use(bodyParser.urlencoded({ extended: true }));

        this.routes.routes(this.app);            
    }
}

exports.default = new App().app;

1 个答案:

答案 0 :(得分:1)

discussion on Claudia's github之后,这似乎是es6与claudia / lambda之间的兼容性问题。

我要做的就是从以下位置更改我的 app.js 文件中的这一行:

exports.default = new App().app;

收件人:

module.exports = new App().app;