【问题标题】:504 timeout in aws EC2 when calling some external api url调用某些外部 api url 时,aws EC2 中的 504 超时
【发布时间】:2022-01-04 22:19:27
【问题描述】:

我有一个以下Next.js api 路由用于测试目的。

所有 4 个 axois 调用都可以在 localhost 中完美运行; 但是在生产中(由 AWS EC2 托管); 最后 2 次调用失败,原因为 504 gateway time-out

我曾想过 nginx 和 AWS in-bound/out-bound 设置,但如果是这样的话,前两个模拟 api 应该也不能正常工作。

我不知道为什么会这样。或者它与那些网站的 api 保护有关? 但是为什么它在本地主机中工作

import axios from "axios";
import { NextApiHandler } from "next";

export default const MockApi: NextApiHandler = async (req, res) => {
  try {
    // mock set
    // work in localhost and production
    const { data: testData } = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
    console.log(testData);

    const { data: mockData } = await axios.get("https://reqres.in/api/users?page=2");
    console.log(mockData);

    // some real life api
    // work in localhost but failed in production with 504 gateway time-out
    const { data: mockData2 } = await axios.get("https://www.target.com.au/ws-api/v1/target/products/search?category=W95362");
    console.log(mockData2);

    const { data } = await axios.get("https://api.nasdaq.com/api/ipo/calendar");
    console.log(data);

    res.status(200).send({});
  } catch (err) {
    res.status(403).json(err);
  }
};

【问题讨论】:

    标签: node.js nginx amazon-ec2 axios next.js


    【解决方案1】:

    经调查,问题似乎与 AWS 内部政策有关,因此您无法使用 AWS 服务滥用特定关联公司和某些公共 API。

    如果有人能够解决问题,则此答案可能不正确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-30
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 2020-11-14
      • 2015-07-29
      • 2018-08-14
      • 1970-01-01
      相关资源
      最近更新 更多