搜索了几个小时之后,我想不出如何在我的项目中正确运行,claudia,create,。
在.aws/credentials之后,我创建了一个组和一个用户-- AWS控制台,然后将这些键添加到我的本管文件中。
然后运行以下命令,正确地生成了lambda.js文件:
来源dist生成无服务器快递代理快速模块应用程序
我的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函数:
克劳迪娅创建-源域-配置文件-处理程序lambda.handler -部署-代理api-区域eu-west-1
但我发现了一个错误:
验证包TypeError:“侦听器”参数必须是_addListener (events.js:239:11) at Server.addListener (events.js:297:10) at new Server (_http_server.js:269:10) at Object.createServer (http.js:34:10) at Object.createServer http.js:34:10 at Object的函数。(/tmp/IiRPif/my-project-1.0.0-1Yh6Wb/package/lambda.js:13:37) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load在initEnvVarsFromOptions.then.then.then.then.then.then.then.dir (/usr/local/lib/node_modules/claudia/src/commands/create.js:342:10)的validatePackage ( Module.require /module.js:11:18)中,Module.require (module.js:596:17)不能在清洁安装后要求。/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;发布于 2018-08-14 12:14:07
在论克劳迪娅的github之后,这似乎是es6和claudia/lambda之间的兼容性问题。
我所需要做的就是将我的app.js文件中的这一行更改为:
exports.default = new App().app;致:
module.exports = new App().app;https://stackoverflow.com/questions/51824413
复制相似问题