aws apigateway的反应不一致

时间:2016-11-09 21:05:29

标签: amazon-web-services aws-api-gateway

我在apigateway控制台中创建了一个API,它作为运行java应用程序的后端服务器的http代理。我们部署了api,创建了一个自定义域,用于通过cloudfront托管它。现在,当我在我的Web应用程序中使用新的cloundfront URL时,某些API不会立即返回。即使使用curl命令

,也可以注意到相同的行为
curl -v -H "Cookie:session_token=llzAwur3FZS78po6b21FEgvXzDUFY3" https://xyz.execute-api.us-east-1.amazonaws.com/test/api/folder/roo

相同的API端点会有不同的响应时间(有时大约是1秒,有时可能是几秒钟)。有时它也会超时。后端服务器(jetty)请求日志显示响应是即时发送的。我们如何调查我们的APIgateway部署出了什么问题?

例如,我有来自网关的这两个响应。坏的

< HTTP/1.1 504 Gateway Time-out
< Content-Type: text/html
< Content-Length: 669
< Connection: keep-alive
< Server: CloudFront
< Date: Fri, 11 Nov 2016 12:27:14 GMT
< X-Cache: Error from cloudfront
< Via: 1.1 xyz.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: Wfjk3bqdwhAbFQhzerMd0DJ5t_2xAF6E_NUTvqif1p9cb9E-jy0GUw==
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
CloudFront attempted to establish a connection with the origin, but either the attempt failed or the origin closed the connection.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: 881Muk_9up7A0phYvmmchNkYWj16yFCsthuKFivS2vbtpULtCk9lnw==
</PRE>
<ADDRESS>
</ADDRESS>
* Connection #0 to host ulj2mxzix6.execute-api.us-east-1.amazonaws.com left intact
</BODY></HTML>

而这 - 好人

< HTTP/1.1 200 OK
< Content-Type: application/json;charset=UTF-8
< Content-Length: 1839
< Connection: keep-alive
< Date: Fri, 11 Nov 2016 12:28:43 GMT
< x-amzn-Remapped-Connection: keep-alive
< x-amzn-Remapped-Content-Length: 1839
< x-amzn-Remapped-Date: Fri, 11 Nov 2016 12:28:43 GMT
< x-amzn-Remapped-Server: nginx/1.4.6 (Ubuntu)
< x-amzn-RequestId: 621bff67-a80a-11e6-bb0a-1bc973821ef5
< X-Cache: Miss from cloudfront
< Via: 1.1 1d43f56d3213a63608863fd0e49585b9.cloudfront.net (CloudFront)
< X-Amz-Cf-Id: ZGwu2NAXKCouMssDjHwSnjyWXe4OFukmeyL7nzC_Y4Lz6QnixdhbEg==

EDIT /分辨率:

如下面的答案中所述,我必须禁用标头以获取响应标头中的内容长度。我正在使用Spring MVC进行REST API实现,并且添加下面的过滤器似乎已经完成了这个技巧

<filter>
        <filter-name>bufferFilter</filter-name>
        <filter-class>org.springframework.web.filter.ShallowEtagHeaderFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>bufferFilter</filter-name>
        <url-pattern>/api/*</url-pattern>
    </filter-mapping>

1 个答案:

答案 0 :(得分:0)

当您的后端使用Transfer-Encoding: chunked时,通常会导致此错误。

我们正在推动更新服务以缓解此问题,但与此同时,您可能希望从后端禁用分块编码。