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 Risposta
1
Risposta accettata

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

See here for the relevant documentation.

AWS
con risposta un mese fa
profile picture
ESPERTO
verificato un mese fa
  • 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.

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande