AWS API gateway routing

0

I have a couple of REST APIs, A and B in API gateway with custom domain "app.example.com" mapped to REST API A and "app.example.com/dev" mapped to REST API B.

  • REST API A is integrated to a serverless app (Lambda) and is working fine as expected.
  • REST API B is integrated to an application running in EC2 using HTTP endpoint as proxy. When using EC2 endpoint directly the app works fine but not via API gateway. When I open the app.example.com/dev, it only returns the base (/) or index.html of the app without loading any static files. I checked the log, all the requests are loaded as "GET / HTTP1.1" even if I ask for other files such as /dev/static/js/index.js. I tried with a simple html app with a js and css file, same issue. I enabled all binary media file types as well. The thing is I have configured another app from another EC2 instance last year using the similar way which is working fine at app.example.com/uat.
reeves
已提問 1 個月前檢視次數 206 次
1 個回答
1
已接受的答案

You need your REST API B path parameter to be set like this /dev/{proxy+}.

See here for the relevant documentation.

AWS
已回答 1 個月前
profile picture
專家
已審閱 1 個月前
  • Thanks for response. Your suggestion can be used only if I create another resource in the REST API A with path /dev. But I using separate REST API B which I added to the API mapping with path /dev. Both do the same thing. Like your suggestion I added /dev/{proxy+} in REST API B, in this case I have to use the url app.example.com/dev/dev but still the same issue. Another thing worth mentioning is though js/css files return 200, the Content-Type is always text/html instead of application/javascript or text/css. Nginx in the EC2 side has no issue & mime types are properly configured there.

  • Under the resource you created (/dev/{proxy+} or just /{proxy+}) click on the method (e.g., ANY) and select the Integration request tab. Edit the Integration request settings and replace the Endpoint URL to be "http://<your_domain>/{proxy}" instead of just "http://<your_domain>" (note that it's proxy without plus sign) Deploy the API and wait few seconds for the configuration to to take affect. This will cause the API to maintain the original request path toward the backend server. Please update if this solves your problem.

  • This http://<your_domain>/{proxy} does the trick. Thanks a lot. We can close this.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南