我创建一个AWS API Gateway Lambda。无服务器部署后,当我尝试获取端点时,它会继续返回{“ message”:“内部服务器错误”}此错误。 我尝试了从互联网上找到的多种解决方案,但没有任何帮助。我不确定我是否对处理程序正确。谢谢。
serverless.ylm
service: back-end
provider:
name: aws
runtime: nodejs12.x
stage: dev
region: us-east-1
memorySize: 384
functions:
app:
handler: app/app.handler
events:
- http:
path: /
method: ANY
cors: true
- http:
path: /{proxy+}
method: ANY
cors: true
app.js
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const db= require('./dbconfig.js');
const cors = require('cors');
const expressValidator = require('express-validator');
//routers
var indexRouter = require('./routes/index');
var mentorRouter = require('./routes/api/mentor');
var universityRouter = require("./routes/api/university");
var bookingsRouter = require("./routes/api/bookings");
var authRouter = require('./routes/api/auth');
var settingRouter = require('./routes/api/setting');
var paywallRouter = require('./routes/api/pay');
const serverless = require('serverless-http');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, './public')));
app.use(logger('dev'));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cookieParser());
app.use(expressValidator());
app.use(cors());
app.use('/', indexRouter);
app.use('/auth', authRouter);
app.use('/mentor', mentorRouter);
app.use('/setting',settingRouter);
app.use('/pay',paywallRouter);
app.use('/api/universities', universityRouter);
app.use('/api/bookings', bookingsRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
//module.exports = app;
module.exports.handler = serverless(app);
答案 0 :(得分:0)
确保API网关具有调用Lambda的正确权限...
https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-lambda-stage-variable-500/
如果这不能解决问题,请检查CloudWatch以获取Lambda日志组中的任何错误见解。确保还启用了CloudWatch Logs。
https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-cloudwatch-logs/