在搜索了几个小时后,我无法弄清楚如何在我的项目中正确运行claudia create 。
按照这个教程,我在 AWS 控制台中创建了一个组和一个用户,然后我将密钥添加到了我的.aws/credentials文件中。
然后我运行了正确生成 lambda.js 文件的命令:
claudia --source dist generate-serverless-express-proxy --express-module app
我的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) 处的函数,位于新服务器 (_http_server.js:269:10) 处.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 (模块.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;