![](/img/trans.png)
[英]why does this AWS Lambda code in Java return "internal server error" when invoked via an API gateway?
[英]NodeJS Api gives Internal Server Error on AWS Lambda
我開發了一個 serverless API,它在 serverless-offline 上運行良好。 它從 AWS RDS 數據庫返回行。 但是當在 AWS Lambda 上部署相同的路由時,路由會給我內部服務器錯誤。 我試過了:
下面是我的代碼:
應用程序.js 文件:
const express = require('express');
const app = express();
const bodyParser = require("body-parser");
app.use(bodyParser.json());
const cors = require('cors')
app.use(cors());
const client = require('./connection.js')
client.connect();
app.get('/', (req, res) => {
res.send('Welcome to API that helps connect with Recruitment DB')
})
app.get('/users', async function (req, res) {
try {
const allProfiles = await client.query("SELECT * FROM public.portal_users");
res.status(200).send(allProfiles.rows);
} catch (error) {
res.status(500).send("Error received: "+ error.message);
}
})
module.exports = app
無服務器.yml 文件:
service: portalserver
frameworkVersion: '3'
provider:
name: aws
memorySize: 2048
stage: dev
timeout: 15
runtime: nodejs12.x
region: ap-south-1
functions:
hello:
handler: handler.hello
events:
- http:
path: /
method: get
cors: true
- http:
path: /{proxy+}
method: any
cors: true
plugins:
- serverless-offline
custom:
serverless-offline:
noPrependStageInUrl: true
get / 運行良好,但 /users 返回內部服務器錯誤
好的,所以問題與訪問有關。 我為我的 lambda function 創建了一個 VPC 來訪問受保護的 AWS RDS 數據庫,它工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.