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 Respuesta
1
Respuesta aceptada

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
EXPERTO
respondido hace un año
  • 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.

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas