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.
1 Answer
1
Accepted Answer

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

See here for the relevant documentation.

AWS
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions