【问题标题】:axios get request Error: Request failed with status code 504axios 获取请求错误:请求失败,状态码 504
【发布时间】:2020-03-29 20:26:04
【问题描述】:

这是我的代码,它从 Amazon Fargate 服务上运行的服务之一向 API 端点发出 Http Get 请求。该 API 由 Amazon API 网关和 Lambda 提供支持。这也是在 VPC 中使用的私有 api,我还设置了 apigateway VPC 端点以促进相同的操作。我只收到过一次这个错误。随后对 API 的所有调用均成功。

我怀疑 lambda 不温暖,导致超时。我将尝试为 axios 代码设置超时。欢迎任何建议

async getItems(): Promise < any > {
  try {

    let url = `https://vpce-[id].execute-api.ap-southeast-2.vpce.amazonaws.com/prod/items`


    const response = await axios.get(url, {
      headers: {
        'Authorization': `Bearer ${token}`,
        'x-apigw-api-id': `[api-id]`
      }
    });

    return response.data;

  } catch(error) {
    console.log(error);
    throw error;
  }
}

【问题讨论】:

    标签: node.js amazon-web-services aws-lambda axios


    【解决方案1】:

    原来我的 lambda 在配置的 30 秒后超时。我可以增加 lambda 超时,但 API 网关的可配置超时为 30 秒。

    它只发生过一次,我相信这是因为 lambda 冷启动。作为一种解决方法,我采用retry 方法。 API 请求将被重试 3 次。

    【讨论】:

      猜你喜欢
      • 2019-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      • 2021-04-10
      • 2021-01-12
      • 2020-10-21
      相关资源
      最近更新 更多