Skip to content

Instantly share code, notes, and snippets.

@asbubam
Last active March 7, 2021 05:47
Show Gist options
  • Save asbubam/c93fc504bccb1d74319862023a22e354 to your computer and use it in GitHub Desktop.
Save asbubam/c93fc504bccb1d74319862023a22e354 to your computer and use it in GitHub Desktop.
Checking current all AWS lambda function's total/provisioned/reserved count.
const AWS = require('aws-sdk');
const lambda = new AWS.Lambda({ region: 'ap-northeast-2' });
const sleep = async (ms) => { await new Promise(resolve => setTimeout(resolve, ms)); };
const getFuncList = async () => {
let funcList = [];
let isStop = false;
let params = {}
while (!isStop) {
await sleep(500);
let data = await lambda.listFunctions(params).promise();
funcList.push(...data.Functions);
params.Marker = data.NextMarker;
if (!data.NextMarker) isStop = true;
}
return funcList;
};
const getProvisionConfig = async (funcName) => {
let data = await lambda.listProvisionedConcurrencyConfigs({ FunctionName: funcName }).promise();
let config;
if (data.ProvisionedConcurrencyConfigs.length > 0) {
config = data.ProvisionedConcurrencyConfigs[0];
console.log(`${funcName}, [${config.AllocatedProvisionedConcurrentExecutions} / ${config.RequestedProvisionedConcurrentExecutions}]`);
if (data.ProvisionedConcurrencyConfigs.length > 1) {
console.log(data.ProvisionedConcurrencyConfigs);
}
}
return config? config.AllocatedProvisionedConcurrentExecutions : 0;
};
const getReservedConfig = async (funcName) => {
let data = await lambda.getFunctionConcurrency({ FunctionName: funcName }).promise();
if (data.ReservedConcurrentExecutions) {
console.log(`${funcName}, ${data.ReservedConcurrentExecutions}`);
}
};
(async () => {
let funcList= await getFuncList();
console.log(`total lambda counts, ${funcList.length}`);
console.log('>>> provisioned');
let totalCount = 0;
for (let i = 0; i < funcList.length; i++) {
await sleep(100);
func = funcList[i];
totalCount += await getProvisionConfig(func.FunctionName);
}
console.log(totalCount);
console.log('>>> reserved');
for (let i = 0; i < funcList.length; i++) {
func = funcList[i];
await getReservedConfig(func.FunctionName);
}
})();
@asbubam
Copy link
Author

asbubam commented Mar 6, 2021

Checking current all AWS lambda function's total/provisioned/reserved count.

  • ex)
$ node check_provision.js
total lambda counts, 200
>>> provisioned
function_name_1, [10 / 10]
function_name_2, [2 / 2]
...
100 # total provisioned count
>>> reserved
function_name_3, 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment