【问题标题】:API Gateway making calls to Application Load Balancer endpoint in front of a micro service deployed in Amazon ECSAPI Gateway 在 Amazon ECS 中部署的微服务前调用 Application Load Balancer 端点
【发布时间】:2017-02-06 22:07:53
【问题描述】:

我在 ECS 集群中部署了微服务,其中应用程序负载均衡器和目标组配置为它的前端。

现在,我在使用应用程序负载平衡器时遇到的一个问题是,有时响应需要超过 3 秒。我正在尝试调查它发生了什么。

现在,当我在 API 网关中创建资源和 POST 方法并将 HTTP 端点配置为服务的应用程序负载均衡器时,我看到的是在某些情况下它会给出以下错误:

Status: 504
Latency: 3026 ms
Response Body
{
  "message": "Network error communicating with endpoint"
}


Execution log for request test-request
Mon Feb 06 21:47:00 UTC 2017 : Starting execution for request: test-invoke-request
Mon Feb 06 21:47:00 UTC 2017 : HTTP Method: POST, Resource Path: /find
Mon Feb 06 21:47:00 UTC 2017 : Method request path: {}
Mon Feb 06 21:47:00 UTC 2017 : Method request query string: {}
Mon Feb 06 21:47:00 UTC 2017 : Method request headers: {}
Mon Feb 06 21:47:00 UTC 2017 : Method request body before transformations: 
Mon Feb 06 21:47:00 UTC 2017 : Endpoint request URI: http://microservice-alb-xxxxxxx.us-east-1.elb.amazonaws.com/find
Mon Feb 06 21:47:00 UTC 2017 : Endpoint request headers: {x-amzn-apigateway-api-id=hw4gf0e5ui, Accept=application/json, User-Agent=AmazonAPIGateway_hxyf0t7ui, X-Amzn-Trace-Id=Root=1-456twed4-97d26555a0abcd123413ad35}
Mon Feb 06 21:47:00 UTC 2017 : Endpoint request body after transformations: 
Mon Feb 06 21:47:03 UTC 2017 : Execution failed due to an internal error
Mon Feb 06 21:47:03 UTC 2017 : Method completed with status: 504

有几次它工作正常并给出正确的响应,状态码为 200,有几次它给出上述响应。在 API Gateway 中执行 Test 以及资源部署到阶段并通过阶段访问时的行为也是如此。

我已打开应用程序负载均衡器的访问日志,并通过覆盖 API 网关中的阶段设置启用了云监视日志。但是我没有得到任何关于这个错误的详细信息。

如何解决 API 网关中出现此错误的原因?

谢谢,

兰吉斯

【问题讨论】:

    标签: aws-api-gateway amazon-ecs


    【解决方案1】:

    我唯一一次看到带有 ALB 的 504 是当 ALB 部署在只有一个可用区的集群前面时。 ALB 需要多个 AZ,当 ALB 尝试在其他 AZ 中搜索路由时,您将获得随机超时。

    如果您排除了 ALB,那么您的 API Gateway 代码中可能会出现问题。我会在那里简化事情,你有自定义验证器吗?如果是这样,则在调试时缓存凭据。如果您还没有使用新的直通映射,也可以更轻松地进行测试。

    【讨论】:

      【解决方案2】:

      对我来说,这个非常神秘的 AWS 错误(“由于内部错误导致执行失败”)是通过不将任何响应标头设置为 null 来解决的(即使当前文档表明它是允许的)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-17
        • 2019-11-03
        • 2017-02-20
        • 2018-03-11
        • 2021-08-08
        • 2018-06-14
        • 1970-01-01
        • 2020-08-03
        相关资源
        最近更新 更多