Question: 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](https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-lambda/src/main/java/com/amazonaws/services/lambda/model/SubnetIPAddressLimitReachedException.java) and [here](http://docs.aws.amazon.com/sdkforruby/api/Aws/Lambda/Errors/SubnetIPAddressLimitReachedException.html) , but I didn't find any clear explaination of this exception ?

Answer: 
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.
Accessing Resources in a VPC
----------------------------

You can set this up when you create a new function. You can also update an existing function so that it has VPC access. You can configure this feature from the Lambda Console or from the CLI. Here’s how you set it up from the Console:

[![enter image description here](https://i.stack.imgur.com/kvz4F.png)](https://i.stack.imgur.com/kvz4F.png)

That’s all you need to do! Be sure to read [Configuring a Lambda Function to Access Resources in an Amazon VPC](http://docs.aws.amazon.com/lambda/latest/dg/vpc.html) in the Lambda documentation if you have any questions.

Resource link:
--------------

1. [Access Resources in a VPC from Your Lambda Functions](https://aws.amazon.com/blogs/aws/new-access-resources-in-a-vpc-from-your-lambda-functions/)
2. [Accessing the Internet and other AWS Resources in your VPC from AWS
Lambda](http://marcelog.github.io/articles/aws_lambda_internet_vpc.html)