Distributing Traffic to Lambda equally to multiple NAT gateways

0

We have a use case where we need multiple NAT gateways so that the we call some external world api with multiple public IPs(because a single use of IP can be blocked due to high traffic). I have created a vpc with private subnets and public subnet associated with each AZ, and a unique NAT gateway for each AZ. so i have 3 private subnet, 3 public subnet and 3 NAT Gateways.

I have created a lambda and associated all 3 private subnets to that. As per AWS documentation: "When an Amazon VPC-connected Lambda function makes requests, it randomly selects an associated subnet.". Can we somehow force some thing like load balancer which will distribute the request equally to each subnet. So that it would go through each public IP equally.

1 Answer
1
Accepted Answer

Hi,

No, you cannot control how to balance traffic natively with lambda.

I have seen cases where for instance, an API Gateway would have an Application Load balancer behind it. Then the ALB would have target groups pointing to lambdas, but at least you can have ALB deciding the load (round robin, https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/how-elastic-load-balancing-works.html).

With that approach you get some kinda of control, thought at subnet level lambda May still select randomly the subnet.

Hope it helps ;)

profile picture
EXPERT
answered a year ago
  • Even if you use an ALB, when ALB invokes the Lambda function, the Lambda service will choose the subnet and you have no control over that.

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.

Guidelines for Answering Questions