Last active
March 7, 2021 05:47
-
-
Save asbubam/c93fc504bccb1d74319862023a22e354 to your computer and use it in GitHub Desktop.
Checking current all AWS lambda function's total/provisioned/reserved count.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Checking current all AWS lambda function's total/provisioned/reserved count.
$ 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