Reputation: 1001
I have created an API in apigateway console which acts as http proxy to my backend server running a java application. We deployed the api, created a custom domain for hosting it via cloudfront. Now when I use the new cloundfront URLs in my web application some of the APIs doesn't return immediately. The same behavior can be noticed even with curl command
curl -v -H "Cookie:session_token=llzAwur3FZS78po6b21FEgvXzDUFY3" https://xyz.execute-api.us-east-1.amazonaws.com/test/api/folder/roo
The same API endpoint would have varied response times(sometimes it is about 1 second and sometimes it can be few seconds). Sometimes it times out too. The backend server(jetty) request log shows that the response is sent instantaneously. How can we investigate what is going wrong with our APIgateway deployment?
For example I have these two responses from the gateway. The bad one
< 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>
And this-- the good one
< 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/Resolution:
As mentioned in the answer below I had to disable a header to get the content length in the response headers. I'm using Spring MVC for REST API implementation and adding the below filter seems to have done the trick
<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>
Upvotes: 0
Views: 1503
Reputation: 9030
This error is typically caused when your backend uses Transfer-Encoding: chunked
.
We are pushing an update the service to alleviate this issue, but in the meantime you may want to disable chunked encoding from your backend.
Upvotes: 0