Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How AWS Lambda function throw SubnetIPAddressLimitReachedException?

In one of my project, one of the AWS Lambda function (usually called every minute) invoking another AWS Lambda function inside its function ( using AWSLambdaClient lambdaClient;). sometimes lambdaClient on invocation of lambda function (its not frequent say 4 to 5 time in every hour) throwing SubnetIPAddressLimitReachedException :

2016-11-24 14 <---------------------> INFO xyzHandler:395 - Lambda was not able to set up VPC access for the Lambda function because one or more configured subnets has no available IP addresses. (Service: AWSLambda; Status Code: 502; Error Code: SubnetIPAddressLimitReachedException; Request ID: XXXX)

I searched here and here , but I didn't find any clear explaination of this exception ?

like image 954
Sumit Arora Avatar asked Jun 28 '26 05:06

Sumit Arora


1 Answers

When your Lambda function is configured to execute inside your VPC, you specify one or more subnet IDs in which the Lambda function will execute.

The subnets that you specify needs to have enough free IP addresses inside them to accomodate all of the simultaneous executions of your Lambda function.

For example, if you choose one subnet and it is defined as a /24, then you have at most 254 or so IP addresses.

If your Lambda function(s) are called 300 times simultaneously, they're going to need 300 individual IP addresses, which your subnet cannot accomodate. In this case, you will get the SubnetIPAddressLimitReachedException error.

When Lambda functions complete, their resources will be reused. So they will free up the used IP addresses and/or re-use them during subsequent Lambda executions.

There is currently no way to limit the number of simultaneous executions within Lambda itself. I've seen people use other services, such as Kinesis, to limit it.

There are 3 avenues of resolution:

  1. If your Lambda function does not need to execute within your VPC, and/or access resources from within your VPC, move it out of the VPC.
  2. Specify more or different subnet IDs with more available IP addresses.
  3. Modify your Lambda function to not call other Lambda functions. The root Lambda function and the subsequently called Lambda functions will each require an IP address.
like image 148
Matt Houser Avatar answered Jul 02 '26 06:07

Matt Houser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!