Architecture public and private API Gateway Endpoints

Hello everyone,

I’m facing a tricky request and I’m not quite sure how to design the infrastructure. Your help would be much appreciated :slight_smile:

Current situation:

I have a distributed application which includes a number of Lambdas behind public API Gateway Endpoints.
For authentication I’m using a Cognito User Pool (backed by a OIDC provider). The API Gateways are secured by a custom authorizer function which validates the token from a received Cookie (the default Cognito authorizer cannot handle Cookies).
The Gateways are reached by a custom domain (Hosted Zone in Route53) and use API Mappings to map to different Gateways. For example we have api.myapp.com with mappings for /service1 → Service1 API Gateway, /service2 → Service 2 API Gateway. This way all APIs are reachable under one domain which makes Cookie handling much easier, since we are always dealing with the same domain. Comparable to a reverse proxy.
The application also includes a number of S3 Buckets, but I don’t want to focus on them right now.

Request:

The customer has an on premises network without access to the public internet. They want the application to be reachable from the network using a connected VPC. The application should still be reachable from the internet for other users.

Problems:

As I understood, one would deploy additional private API Gateways and connect them to the VPC using an Interface Endpoint.
Private Endpoints do not support custom domain names, therefore one would have to add the domain name to the VPC itself. AWS would automatically add Route53 entries for the VPC, therefore I would need to use a different domain than the already used domain in the public endpoints.
Are both assumptions correct?
If I made the VPC reachable under the second domain name, I would still not have my API mappings. I cannot use the cryptic AWS generated URLs since I use Cookie auth and therefore need one unified domain name.

I’m not quite sure where to go from here. These are the options I can think of:

  • Use some kind of reverse proxy (maybe AWS Application Load Balancer?) inside the VPC to re-route to the API Gateways. In the old days I would have just spun up NGINX.
  • Just use cryptic AWS URLs and use headers instead of Cookie auth. This would probably be the easiest approach, but Cookie auth is an absolute requirement by the customer.
  • Leave all as it is and convince them to whitelist the applications public URLs in their on-premises network.

Any help would be very much appreciated! I cannot really find any best practice or guidance on how to handle this.

Thank you!

With a private DNS zone you can achieve split DNS scenarios with route53 if my memory serves me correctly. Then you could put your application on the vpc with a private link and use an internal dns zone to put it on the correct domain.

But how would private link solve the issue with path mapping? Doesn’t private link just expose one endpoint?

Use mTLS with your public API Gateway. mTLS ensures that only clients with valid certificates can connect to the API Gateway, essentially allowing private access even from a public endpoint.

I don’t know if it is possible to put an existing api gateway behind a VPC endpoint serving both public and private networks. If that is not the possible, you can mirror your current public setup behind a second “private” api gateway with a VPC endpoint. Then ask your customer to make a dns entry (same domain as the public api) to his systems towards that private endpoint.

Had a similar scenario at my work. Long story short we used the cryptic urls. Aws private rest gateway does not support custom domain out of the box. This is a hard limitation on the service. However, there are ways to do this using load balancers. We did not explore this because we did not want to introduce additional complexity to the system.

My advice would be to simply try and make the cryptic urls work since all other methods introduce additional complexity and maintenance for tour system.

AWS has a whole architecture example for enabling custom domains for for private APIs. It basically consists of placing an NLB in front of the execute-api VPC endpoint’s ENIs which can handle your TLS termination with the correct certificate (this is why custom domains don’t usually work privately) and then pass that traffic to the endpoints

https://serverlessland.com/repos/apigw-private-custom-domain-name

I’ve had the same requirements in a corporate environment.

This is the only current option that provides you with private network isolation.

AWS would automatically add Route53 entries for the VPC, therefore I would need to use a different domain than the already used domain in the public endpoints.

No, you can add the same domain and record as long as they are both in separate Hosted Zones. This is a practice I used with a specific client: He needed dev.example.com to point to destination X if it was accessed via the public internet. But if it was accessed via VPC, dev.example.com would go to destination Y.

You can create a Private Zone and assign it to your Public API Gateway, at the end you disable the default endpoint of your API Gateway. Now requests can only come from route53, as your domain is in a private zone, only requests coming from the associated VPC will be resolved.

I’ll look into it, thank you very much :slight_smile:

I got that, but I don’t think it is possible to do path mappings with a second private endpoint. I would need a number of VPC endpoints with some path rewriting (and certificate validation) in front of it (hence the idea with the load balancer). Thank you for the food for thought :slight_smile:

Thank you for your answer :slight_smile: Using the cryptic URLs is not really possible since alle services are part of one application and CORS won’t want the user to do request to X different URLs and send credentials.

Thank you for the insight! Might come in handy :slight_smile:

As I said, the clients are in a network without access to the internet :frowning:

Edit: I remember I already saw that repo. What threw me off was this:
Note that multi-level API mappings, that allow you to control which API receives a request according to mappings between an API and any segment of the request path, do not work with this workaround

I’m using api mappings but only shallow ones (/users, /posts, etc…). I suppose the solution cannot handle deeper level mappings(?).

Yeah I don’t think that should be an issue for you if you’re only doing simple mappings

not sure if its too late. BUT AWS now supports custom domains on private gateway since last year November!!!

Thank you for the update :slight_smile: I had noticed it and played around a bit. I ran into SSL issues, but did not invest too much time after that.

The original requirement was never implemented since priorities had shifted (yet again) :slight_smile: