0
votes

I have configured a set of resources for an API Gateway in Amazon API Gateway. All resources are proxy resource to a three sites. The API Gateway was decided to be used such that the API Key could be unified and the domain could also be unified.

The test through the console was successful, and the responses came inside a second. The logs could be traced from the Cloudwatch since I had enabled detailed logs there.

Attempting the same through the provided url using curl, the final response is absurd, whereas the http endpoint where I am running nginx adds to the access logs almost instantly, and the corresponding Cloudwatch logs also shows proper execution.

Cloudwatch logs

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 command output

< 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==

The above is followed by the standard html page with error message as CloudFront attempted to establish a connection with the origin, but either the attempt failed or the origin closed the connection.

I am dumpfounded, as to whether this is an issue with the cloudfront and the eu-west-1 region, or something which I missed out while configuring the system.

1

1 Answers

1
votes

I've just got the same issue with API Gateway configuration. This is a known CloudFront issue for the header 'Transfer-Encoding=chunked'. As it's not possible to change Integration Response for http_proxy integration the solution from AWS Support is to prevent backend server from sending such headers. As far as I know this haven't been resolved yet..

Regards, Kas