AWS API Gateway – Private Integration Routing Without Path Variables

amazon-api-gatewayamazon-web-services

I've been setting up an HTTP gateway for the first time and came across an issue with private integrations. I want all my integrations to be private but it doesn't work well with routing.

I have a private integration with a $default route and it works great.
Now I want another private integration to be mounted under, say, /microservice/ and have all its endpoints proxied.

This however seems impossible because private integrations ask you for a backend ARN rather than URI, so there's no way to use path variables like {proxy+}. This results in only root of my microservice being accessible through the gateway – all the other paths just go to the $default route.

How would one go about setting up a private integration like this? Ideally I would like something like this:

- /microservice1/{proxy+}
- /microservice2/{proxy+}
- $default

Currently as I understand it I only have two options:

  • Expose my services to the world and use public integration with greedy path variables {proxy+} – not ideal
  • Keep the private integration but define each microservice endpoint as it's own route on the gateway – extremely annoying to maintain

Is there a good way to do this that I'm missing?

Best Answer

To answer my own question - this is possible with request parameter mapping that transforms request before it reaches the backend:

  1. Create a route with greedy path variable: /microservice/${proxy}
  2. In your private integration create a path mapping: overwrite:path = /$request.path.proxy