即使在 API 网关日志正确之后,Cloudfront 超时

Cloudfront timesout even after API Gateway logs are correct

我已经为 Amazon API 网关中的 API 网关配置了一组资源。所有资源都是三个站点的代理资源。决定使用API网关,这样就可以统一API Key,也可以统一域。

通过控制台测试成功,一秒内有响应。由于我在那里启用了详细日志,因此可以从 Cloudwatch 跟踪日志。

使用 curl 通过提供的 url 尝试相同的操作,最终的响应是荒谬的,而我 运行 nginx 所在的 http 端点几乎立即添加到访问日志中,相应的 Cloudwatch 日志也显示正确执行。

Cloudwatch 日志

08:36:20 Usage Plan check succeeded for API Key **********************************fpqlo7 and API Stage bzfet1144f/v3 
08:36:20 Starting execution for request: 29b3d251-9fe0-11e6-8dd6-93361a1890a5
08:36:20 HTTP Method: GET, Resource Path: /app/coupon/p/12356
08:36:20 API Key: **********************************fpqlo7
08:36:20 Method request path: {proxy=coupon/p/12356}
08:36:20 Method request query string: {}
08:36:20 Method request headers: {Accept=*/*, CloudFront-Viewer-Country=IN, CloudFront-Forwarded-Proto=https, CloudFront-Is-Tablet-Viewer=false, CloudFront-Is-Mobile-Viewer=false, User-Agent=Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36, X-Forwarded-Proto=https, CloudFront-Is-SmartTV-Viewer=false, Host=bzfet1144f.execute-api.eu-west-1.amazonaws.com, X
08:36:20 Method request body before transformations: null
08:36:20 Endpoint request URI: http://*****************/app/coupon/p/12356
08:36:20 Endpoint request headers: {x-amzn-apigateway-api-id=bzfet1144f, Accept=*/*, CloudFront-Viewer-Country=IN, CloudFront-Forwarded-Proto=https, CloudFront-Is-Tablet-Viewer=false, User-Agent=Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36, CloudFront-Is-Mobile-Viewer=false, X-Forwarded-Proto=https, CloudFront-Is-SmartTV-Viewer=false, Host=bzfet1144f
08:36:20 Endpoint request body after transformations: null
08:36:20 Endpoint response body before transformations: [["\/app\/coupon\/p\/12356","coupon\/p\/12356"]]
08:36:20 Endpoint response headers: {Transfer-Encoding=chunked, Server=nginx/1.4.6 (Ubuntu), Cache-Control=no-cache, must-revalidate, Connection=keep-alive, Vary=Accept-Encoding, Date=Tue, 01 Nov 2016 03:06:35 GMT, Content-Type=application/json}
08:36:20 Method response body after transformations: [["\/app\/coupon\/p\/12356","coupon\/p\/12356"]]
08:36:20 Method response headers: {Transfer-Encoding=chunked, Server=nginx/1.4.6 (Ubuntu), Cache-Control=no-cache, must-revalidate, Connection=keep-alive, Vary=Accept-Encoding, Date=Tue, 01 Nov 2016 03:06:35 GMT, Content-Type=application/json}
08:36:20 Successfully completed execution
08:36:20 Method completed with status: 200

Curl命令输出

< HTTP/1.1 504 Gateway Time-out
< Content-Type: text/html
< Content-Length: 669
< Connection: keep-alive
* Server CloudFront is not blacklisted
< Server: CloudFront
< Date: Tue, 01 Nov 2016 03:06:50 GMT
< X-Cache: Error from cloudfront
< Via: 1.1 d11c243977c97aea69643cb52490b7e9.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: tVsfEoAXfG9KuEVgw9S9YP98z4DPayqeCdvlIbCPayjRHaS5QvUOuQ==

上面是带有错误消息的标准 html 页面,因为 CloudFront 尝试与源建立连接,但尝试失败或源关闭了连接。

我很震惊,这是云端和 eu-west-1 区域的问题,还是我在配置系统时遗漏的问题。

我刚刚遇到了与 API 网关配置相同的问题。这是 header 'Transfer-Encoding=chunked' 的已知 CloudFront 问题。由于无法更改 http_proxy 集成的集成响应,AWS Support 的解决方案是防止后端服务器发送此类 header。据我所知这还没有解决..

此致, 卡斯