We did quick experiment on AWS lambda to confirm concurrent execution limit based on our VPC IP limit? In our AWS account VPC has around 500 IPs available. In general, if AWS lambda is running inside VPC, available IPs can be exhausted if we have more concurrent lambda's running than available IPs. Below are the experiment details and Lambda functions.
We wrote a lambda caller (refer#1 below) function which invokes lambda called function (refer#2) configured inside VPC. We invoked a lambda called function around 999 times and made sure that all these should run concurrently. But surprisingly all lambda's finished without any complain.
The biggest question is, if we had 500 IP limit in our VPC and we ran lambda 999 times inside VPC, why we didn't get IP availability issue? Any idea?
1. Lambda Caller Function (Node.js 10.x)
const AWS = require('aws-sdk');
const lambda = new AWS.Lambda();
const duration = 3 * 60 * 1000;
exports.handler = async (event) => {
try {
const lambdaPosterParams = {
FunctionName: 'testCalledFunction',
InvocationType: 'Event',
LogType: 'None'
};
for (var invokationNumber=0; invokationNumber<999; invokationNumber++) {
console.log("Invoking lambda #" + invokationNumber);
lambdaPosterParams.Payload = JSON.stringify({
'invokationNumber': invokationNumber,
'duration': duration,
'tableName': 'testload2'
});
const posterResponse = await lambda.invoke(lambdaPosterParams).promise();
console.log("Poster Lambda invoked", JSON.stringify(posterResponse));
}
} catch (error){
console.error('Error invoking lambda #' + invokationNumber, error);
throw error;
}
console.log("All lambdas invoked");
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
2. Lambda Called Function (Node.js 10.x)
const AWS = require('aws-sdk');
const dbConnection = new AWS.DynamoDB({region: process.env.AWS_REGION, apiVersion: process.env.AWS_DYNAMODB_API_VERSION});
exports.handler = async (event) => {
const startTime = new Date();
const insertData = {
'TableName': 'testload',
'Item': {
'invokationNumber': {'N': event.invokationNumber.toString()},
'startTime': {'S': startTime.toUTCString()},
}
};
await dbConnection.putItem(insertData).promise();
console.log(`Event #${event.invokationNumber}. Sleeping...`);
await timeout(3 * 60 * 1000);
console.log('Waking up...');
const endTime = new Date();
insertData.Item.endTime = {'S': endTime.toUTCString()};
insertData.Item.duration = {'N': (endTime.getTime() - startTime.getTime()).toString()};
await dbConnection.putItem(insertData).promise();
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
};