@aws-sdk/find-v2 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,14 +8,20 @@ import { getLambdaFunctions } from "./utils/getLambdaFunctions.js";
|
|
|
8
8
|
export const scanLambdaFunctions = async ({ region, yes } = {}) => {
|
|
9
9
|
const client = new Lambda({ region });
|
|
10
10
|
const functions = await getLambdaFunctions(client);
|
|
11
|
-
const totalCodeSize = functions.reduce((acc, fn) => acc + (fn.CodeSize || 0), 0);
|
|
12
11
|
const functionCount = functions.length;
|
|
12
|
+
const concurrency = Math.min(functionCount, cpus().length || 1);
|
|
13
|
+
const codeSizeToDownload = functions.reduce((acc, fn) => acc + (fn.CodeSize || 0), 0);
|
|
14
|
+
const codeSizeToSaveOnDisk = functions
|
|
15
|
+
.map((fn) => fn.CodeSize || 0)
|
|
16
|
+
.sort((a, b) => b - a)
|
|
17
|
+
.slice(0, concurrency)
|
|
18
|
+
.reduce((acc, size) => acc + size, 0);
|
|
13
19
|
if (functionCount === 0) {
|
|
14
20
|
console.log("No functions found.");
|
|
15
21
|
process.exit(0);
|
|
16
22
|
}
|
|
17
23
|
if (!yes) {
|
|
18
|
-
const confirmation = await getDownloadConfirmation(functionCount,
|
|
24
|
+
const confirmation = await getDownloadConfirmation(functionCount, codeSizeToDownload, codeSizeToSaveOnDisk);
|
|
19
25
|
console.log();
|
|
20
26
|
if (!confirmation) {
|
|
21
27
|
console.log("Exiting.");
|
|
@@ -28,7 +34,7 @@ export const scanLambdaFunctions = async ({ region, yes } = {}) => {
|
|
|
28
34
|
console.log(`- ${JS_SDK_V2_MARKER.UNKNOWN} means script was not able to proceed, and it emits reason.\n`);
|
|
29
35
|
const clientRegion = await client.config.region();
|
|
30
36
|
console.log(`Reading ${functionCount} function${functionCount > 1 ? "s" : ""} from "${clientRegion}" region.`);
|
|
31
|
-
const limit = pLimit(
|
|
37
|
+
const limit = pLimit(concurrency);
|
|
32
38
|
await Promise.all(functions.map((fn) => limit(() => scanLambdaFunction(client, fn.FunctionName))));
|
|
33
39
|
console.log("\nDone.");
|
|
34
40
|
};
|
|
@@ -4,21 +4,23 @@ import { getHumanReadableBytes } from "./getHumanReadableBytes.js";
|
|
|
4
4
|
* Prompts user for confirmation before downloading Lambda function code
|
|
5
5
|
*
|
|
6
6
|
* @param functionCount - Number of Lambda functions to be processed
|
|
7
|
-
* @param
|
|
7
|
+
* @param codeSizeToDownload - Total size of all function code in bytes
|
|
8
|
+
* @param codeSizeToSaveOnDisk - Maximum disk space used at any point
|
|
8
9
|
* @returns Promise that resolves to boolean indicating user's choice
|
|
9
10
|
* @description
|
|
10
11
|
* - Creates interactive readline interface for user input
|
|
11
12
|
* - Displays summary of operations including function count and total size
|
|
12
13
|
* - Returns true if user confirms with 'y' or 'yes', false otherwise
|
|
13
14
|
*/
|
|
14
|
-
export const getDownloadConfirmation = async (functionCount,
|
|
15
|
+
export const getDownloadConfirmation = async (functionCount, codeSizeToDownload, codeSizeToSaveOnDisk) => {
|
|
15
16
|
const rl = createInterface({
|
|
16
17
|
input: process.stdin,
|
|
17
18
|
output: process.stdout,
|
|
18
19
|
});
|
|
19
|
-
const answer = await rl.question(`This
|
|
20
|
-
`\
|
|
21
|
-
`\
|
|
20
|
+
const answer = await rl.question(`This command will process ${functionCount} Lambda Node.js functions, and` +
|
|
21
|
+
`\ndownload ${getHumanReadableBytes(codeSizeToDownload)} of compressed archives over the network.` +
|
|
22
|
+
`\nIt'll store maximum of ${getHumanReadableBytes(codeSizeToSaveOnDisk)} on disk at any point.` +
|
|
23
|
+
`\n\nDo you want to continue? (y/N): `);
|
|
22
24
|
rl.close();
|
|
23
25
|
return ["y", "yes"].includes(answer.trim().toLowerCase());
|
|
24
26
|
};
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* @description
|
|
8
8
|
* - Handles edge case where bytes is 0 or negative
|
|
9
9
|
* - Automatically selects appropriate unit (Bytes, KB, MB, GB, etc.)
|
|
10
|
-
* - Uses base-
|
|
10
|
+
* - Uses base-1000 conversion for SI units
|
|
11
11
|
* - Rounds to specified number of decimal places
|
|
12
12
|
*/
|
|
13
13
|
export const getHumanReadableBytes = (bytes, decimals = 2) => {
|
|
14
14
|
if (bytes <= 0)
|
|
15
15
|
return "0 Bytes";
|
|
16
|
-
const k =
|
|
16
|
+
const k = 1000;
|
|
17
17
|
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB"];
|
|
18
18
|
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1);
|
|
19
19
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + " " + sizes[i];
|