Based on what the AWS documentation says, by default each account can have 1000 concurrent Lambda functions executed at a time. Granted that this is a soft limitation and can be changed per request.
Now, my question is how can you monitor your concurrent Lambda function executions anyway?
I'm assuming this should be done (somehow) using CloudWatch. In the Metrics section of the CloudWatch, following this path:
All > Lambda > Across All Functions
You can find a metric by the name ConcurrentExecutions. My bets are on this one but at the same time, I'm not getting the numbers based on the test I've done. Before we get there, the values shown on the graph for this metric are not integers so I'm guessing I'm missing something here. But that's fine. Let me tell you about the test I've conducted.
I have created a simple NodeJs script on an EC2 instance like this:
const AWS = require('aws-sdk');
const https = require('https');
const sslAgent = new https.Agent({
keepAlive: true,
maxSockets: 200,
rejectUnauthorized: true,
});
sslAgent.setMaxListeners(0);
AWS.config.update({
region: 'us-east-1',
httpOptions: {
agent: sslAgent,
},
});
const lambda = new AWS.Lambda();
function call() {
return lambda.invoke({
FunctionName: "test",
Payload: JSON.stringify({
wait: 5000,
}),
}).promise();
}
(async () => {
let start = Date.now();
const promises = [...Array(200).keys()].map(i => {
return call(new Date(Date.now()).toISOString())
.then(data => {
console.log(`Success (${i})`);
})
.catch(err => {
console.log(`Error (${i}): ${err}`);
});
});
await Promise.all(promises);
let end = Date.now();
console.log((new Date(end - start).toISOString()).substr(11, 12));
})();
This script will call a Lambda function (called test) 200 times without waiting for the individual calls to return. On the server side, I have this code in a Lambda function:
exports.handler = async (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return new Promise((resolve) => {
setTimeout(() => {
callback(null, response);
resolve();
}, event.wait);
});
};
This Lambda function will keep the caller hanging for the time passed as the input (in this case 5 seconds). I ran this test and verified that there were 200 instances of the Lambda function running at the same time. And I verified this by going to CloudWatch and looking into generated logs and there were 200 Log Streams generated (each execution has a separate Log Stream).
But when I go the mentioned Metric, the graph shows only a 68.7 which first of all is a bizarre number to show and secondly, it's not 200. So what is this number and where can I find my 200?
