Skip to content

How to get traffic from a public API Gateway to a private one?

0

I would like to use private API Gateways to organise Lambda functions into microservices, while keeping them invisible from the public internet. I would then like to expose specific calls using a public API Gateway.

How do I get traffic from my public API Gateway to a private API Gateway?

What I've looked at so far

In the past, for container-based resources, I've used the following pattern:

Internet -> API Gateway -> VPC Link -> VPC[NLB -> ECS]

However, I can't find an equivalent bridge to get specific traffic to a private API Gateway. I.e.

Internet -> API Gateway -> ? -> Private Gateway -> Lambda

My instinct tells me that a network-based solution should exist (equivalent to VPC Link), but so far the only suggestions I've had involve:

  • Solving using compute ( Internet -> API Gateway -> VPC[Lambda proxy] -> Private Gateway -> Lambda )
  • Solving using load balancers ( Internet -> API Gateway -> VPC Link -> VPC[NLB -> ALB] -> Private Gateway -> Lambda )

Both of these approaches strike me as using the wrong (and expensive!) tools for the job. I.e. Compute where no computation is required and (two!!) load balancers where no load balancing is required (as Lambda effectively self-loadbalances).

Alternative solutions

Perhaps there's a better way (other than a private API Gateway) to organise collections of serverless resources into microservices. I'm attempting to use them to present a like-for-like interface that my container-based microservices would have. E.g. Documented (Open API spec), authentication, traffic monitoring, etc.

If using private API Gateways to wrap internal resources into microservices is actually a misuse, and there's a better way to do it, I'm happy to hear it.

2 Answers
3
Accepted Answer

The only way to get from API Gateway to private resources is using VPC Link, and VPC Link requires an NLB (No need for an ALB between the NLB and the endpoints). So your path will be: Public API -> VPC Link -> NLB -> Private API VPC Endpoint -> Private API.

Saying that, you don't really must use private APIs. you could just protect the internal APIs' endpoints using IAM and the ones that you want public using some other approach (e.g. Cognito).

AWS
EXPERT

answered 4 years ago

EXPERT

reviewed 3 years ago

  • It's unfortunate that the NLB is still required, but at least it's better than both my current suggestions (+1). If no alternatives present themselves in the next 24 hours, I'll mark this as the accepted answer. Thanks!

    Also, you're right about strict IAM + Cognito. And I will be using both in this solution. But I've seen enough loose/misconfigured IAM policies in my time that I'll be a lot more confident with the additional network isolation.

  • @Uri what type of target group would you add to the NLB?

  • Look at point #4 in this blog. It talks about custom domain names for private APIs, but the same idea applies.

  • Ah! Perfect. That's exactly what I was looking for. Marking as accepted. Thank you.

  • I've tried to configure the suggested way (public API's protected by Cognito and private using IAM Authorization) but when configuring a http_proxy from the public (Cognito protected) to the private (IAM protected) I keep getting 'forbidden' errors because a Role with correct policies are not part of the request. How would you configure the integration request to the API Gateway that is protected by IAM Authorization?

0

@Steef

Almost two years later, but there is not much information available about this topic, so an answer could still help the community.

If you want to proxy requests to a Private API Gateway, using the http_proxy integration is not the right approach. A Private API Gateway is accessible only within a VPC, and the correct method to achieve this is by using a VPC Link as mentioned in the first answer.

But If your goal is to restrict access between two Public Api Gateways with IAM authorization, you must ensure that every request is signed with SigV4. This will add IAM credentials to the request. Currently, the only way to achieve this is by using a Lambda integration in Api Gateway B that signs the request and proxies it to the Public API Gateway A. Than you can use the Lambda (execution) role that signs the request in the resource policy of Public Api Gateway A. By default, the http_proxy integration does not include IAM credentials in the request, so the target API Public Gateway (A) cannot recognize it as a request from the origin API Gateway (B). Resource policies won't work in this setup.

However, if you implement the setup as described above—using a VPC Link integration in conjunction with a VPC Endpoint—IAM credentials will be included in the request to the private API Gateway. In this scenario, you can configure a resource policy on the Private API Gateway to allow requests originating from the Public API Gateway. It's an additional layer of security that restrict access within your VPC and here you can allow only the Public API (via the vpc link) to make requests to the Private API Gateway, even if you are in the same VPC and subnet.

answered 2 years ago

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.