You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决AWS API Gateway与Lambda的504网关超时错误?

遇到504 Bad Gateway Timeout错误,但数据已成功插入数据库

错误提示


代码在本地执行完美,响应时间在1.15秒内,但部署到Lambda后就出现此超时错误。

Node.js端点路由如下:

route.post("/Register", async (req, res) => {
  try {
    const user = new userschema({
      Name: req.body.Name,
      Email: req.body.Email,
      UserName: req.body.UserName,
      PhotoUrl: req.body.PhotoUrl,
    });
    await user.save();
    return res.status.send("Created");
  } catch (error) {
    return res.status(500).send("Something Went Wrong");
  }
});

已将Node.js后端部署到运行在VPC中的AWS Lambda,并使用MongoDB Atlas,架构如下

架构示意图

我是AWS新手,因此遵循了某YouTube视频的步骤。

数据已成功插入MongoDB Atlas数据库,因此Lambda函数与MongoDB Atlas之间的VPC Peering连接应该正常。

CloudWatch日志如下:

日志截图1
日志截图2
日志截图3

我已尝试所有可能的方法,但仍面临此问题。


内容的提问来源于stack exchange,提问作者Udbhav Vikram Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 23:10:27