Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway not reverse proxying correctly

I am trying to use AWS API Gateway as a reverse HTTP proxy to front several prototype web applications which are deployed as elastic beanstalk apps:

Configuration

Each EB app is mapped in API Gateway under it's app name e.g.

/hello1 (API Gateway mapping) --> prototype1 EB application 
/hello2 (API Gateway mapping) --> prototype2 EB application
... etc

This is the overall mapping I have created:

enter image description here

It seems that API Gateway treats requests for the root resource in each mapping e.g. '/' differently to requests for sub resources, so I have set up proxy mappings for both:

The root ('/') resource is a straight forward (i.e. non-greedy) proxy mapping:

Root '/' resource proxy mapping

Then there's a greedy proxy mapping for anything underneath the root context:

Greedy proxy mapping under the root context

I then deploy the API to a stage named 'master'

The idea being that to access each prototype I'd GET the URL http://protos.acme.com/<stage>/<proto_name> e.g. http://protos.acme.com/master/hello1.

Problem

I'm finding that if I add a trailing slash to the URL, or specify a particular resource e.g. index.html then everything works perfectly e.g.

  • http://protos.acme.com/master/hello1/ - works fine
  • http://protos.acme.com/master/hello1/index.html - works file

However if I omit the trailing slash from the URL e.g. http://protos.acme.com/master/hello1 then the URL rewriting done by API Gateway stops working and any URLs in the proxied content no longer resolve correctly as they omit the prototype name e.g. http://protos.acme.com/master/index.html.

I can't find any way to configure the behaviour for when the trailing slash is omitted and I don't think it's acceptable to force my users to always remember the trailing slash.

Grateful for any insight!

Edd

like image 425
Edd Grant Avatar asked Oct 20 '25 02:10

Edd Grant


1 Answers

I setup a quick test and it seems to work if I explicitly define a GET method at the resource root path in addition to the ANY {proxy+} path.

api gateway proxy integration

like image 81
Dave Maple Avatar answered Oct 21 '25 17:10

Dave Maple



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!