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.

Kundan
已提問 1 年前檢視次數 319 次
1 個回答
1
已接受的答案

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
專家
已回答 1 年前
  • 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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南