@aws-sdk/find-v2 0.2.0 → 0.3.1
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.
package/dist/cli.js
CHANGED
|
@@ -15,10 +15,11 @@ export const createProgram = () => {
|
|
|
15
15
|
.version(packageJson.version, "-v, --version");
|
|
16
16
|
program
|
|
17
17
|
.command("lambda")
|
|
18
|
-
.description("Scans Lambda Node.js Functions for JavaScript SDK v2
|
|
18
|
+
.description("Scans Lambda Node.js Functions for JavaScript SDK v2")
|
|
19
19
|
.option("-r, --region <region>", "AWS region to scan")
|
|
20
|
+
.option("-y, --yes", "answer yes for all prompts")
|
|
20
21
|
.action(async (options) => {
|
|
21
|
-
await scanLambdaFunctions(options
|
|
22
|
+
await scanLambdaFunctions(options);
|
|
22
23
|
});
|
|
23
24
|
return program;
|
|
24
25
|
};
|
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
import { Lambda
|
|
1
|
+
import { Lambda } from "@aws-sdk/client-lambda";
|
|
2
|
+
import pLimit from "p-limit";
|
|
3
|
+
import { cpus } from "node:os";
|
|
2
4
|
import { JS_SDK_V2_MARKER } from "./constants.js";
|
|
3
5
|
import { scanLambdaFunction } from "./scanLambdaFunction.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.filter((fnName) => fnName !== undefined);
|
|
8
|
-
export const scanLambdaFunctions = async (region) => {
|
|
6
|
+
import { getDownloadConfirmation } from "./utils/getDownloadConfirmation.js";
|
|
7
|
+
import { getLambdaFunctions } from "./utils/getLambdaFunctions.js";
|
|
8
|
+
export const scanLambdaFunctions = async ({ region, yes } = {}) => {
|
|
9
9
|
const client = new Lambda({ region });
|
|
10
|
-
const functions =
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
const functionsLength = functions.length;
|
|
16
|
-
if (functionsLength === 0) {
|
|
10
|
+
const functions = await getLambdaFunctions(client);
|
|
11
|
+
const totalCodeSize = functions.reduce((acc, fn) => acc + (fn.CodeSize || 0), 0);
|
|
12
|
+
const functionCount = functions.length;
|
|
13
|
+
if (functionCount === 0) {
|
|
17
14
|
console.log("No functions found.");
|
|
18
15
|
process.exit(0);
|
|
19
16
|
}
|
|
17
|
+
if (!yes) {
|
|
18
|
+
const confirmation = await getDownloadConfirmation(functionCount, totalCodeSize);
|
|
19
|
+
console.log();
|
|
20
|
+
if (!confirmation) {
|
|
21
|
+
console.log("Exiting.");
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
20
25
|
console.log(`Note about output:`);
|
|
21
26
|
console.log(`- ${JS_SDK_V2_MARKER.Y} means "aws-sdk" is found in Lambda function, and migration is recommended.`);
|
|
22
27
|
console.log(`- ${JS_SDK_V2_MARKER.N} means "aws-sdk" is not found in Lambda function.`);
|
|
23
28
|
console.log(`- ${JS_SDK_V2_MARKER.UNKNOWN} means script was not able to proceed, and it emits reason.\n`);
|
|
24
29
|
const clientRegion = await client.config.region();
|
|
25
|
-
console.log(`Reading ${
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
30
|
+
console.log(`Reading ${functionCount} function${functionCount > 1 ? "s" : ""} from "${clientRegion}" region.`);
|
|
31
|
+
const limit = pLimit(Math.min(functionCount, cpus().length || 1));
|
|
32
|
+
await Promise.all(functions.map((fn) => limit(() => scanLambdaFunction(client, fn.FunctionName))));
|
|
29
33
|
console.log("\nDone.");
|
|
30
34
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { getHumanReadableBytes } from "./getHumanReadableBytes.js";
|
|
3
|
+
/**
|
|
4
|
+
* Prompts user for confirmation before downloading Lambda function code
|
|
5
|
+
*
|
|
6
|
+
* @param functionCount - Number of Lambda functions to be processed
|
|
7
|
+
* @param totalCodeSize - Total size of all function code in bytes
|
|
8
|
+
* @returns Promise that resolves to boolean indicating user's choice
|
|
9
|
+
* @description
|
|
10
|
+
* - Creates interactive readline interface for user input
|
|
11
|
+
* - Displays summary of operations including function count and total size
|
|
12
|
+
* - Returns true if user confirms with 'y' or 'yes', false otherwise
|
|
13
|
+
*/
|
|
14
|
+
export const getDownloadConfirmation = async (functionCount, totalCodeSize) => {
|
|
15
|
+
const rl = createInterface({
|
|
16
|
+
input: process.stdin,
|
|
17
|
+
output: process.stdout,
|
|
18
|
+
});
|
|
19
|
+
const answer = await rl.question(`This script will process ${functionCount} Lambda Node.js functions,` +
|
|
20
|
+
`\nand download ${getHumanReadableBytes(totalCodeSize)} of compressed archives over the network.` +
|
|
21
|
+
`\nDo you want to continue? (y/N): `);
|
|
22
|
+
rl.close();
|
|
23
|
+
return ["y", "yes"].includes(answer.trim().toLowerCase());
|
|
24
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts bytes to human readable format with appropriate units
|
|
3
|
+
*
|
|
4
|
+
* @param bytes - Size in bytes to convert
|
|
5
|
+
* @param decimals - Number of decimal places to show (default: 2)
|
|
6
|
+
* @returns String representation of size with unit (e.g., "1.50 MB")
|
|
7
|
+
* @description
|
|
8
|
+
* - Handles edge case where bytes is 0 or negative
|
|
9
|
+
* - Automatically selects appropriate unit (Bytes, KB, MB, GB, etc.)
|
|
10
|
+
* - Uses base-1024 conversion for binary units
|
|
11
|
+
* - Rounds to specified number of decimal places
|
|
12
|
+
*/
|
|
13
|
+
export const getHumanReadableBytes = (bytes, decimals = 2) => {
|
|
14
|
+
if (bytes <= 0)
|
|
15
|
+
return "0 Bytes";
|
|
16
|
+
const k = 1024;
|
|
17
|
+
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB"];
|
|
18
|
+
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1);
|
|
19
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + " " + sizes[i];
|
|
20
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { paginateListFunctions } from "@aws-sdk/client-lambda";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves all Lambda functions with Node.js runtime from AWS
|
|
4
|
+
*
|
|
5
|
+
* @param client - AWS Lambda client instance
|
|
6
|
+
* @returns Promise that resolves to array of Lambda function configurations
|
|
7
|
+
* @description
|
|
8
|
+
* - Uses AWS SDK v3 pagination to handle large number of functions
|
|
9
|
+
* - Filters results to only include Node.js runtimes
|
|
10
|
+
* - Returns empty array if no functions found
|
|
11
|
+
*/
|
|
12
|
+
export const getLambdaFunctions = async (client) => {
|
|
13
|
+
const functions = [];
|
|
14
|
+
const paginator = paginateListFunctions({ client }, {});
|
|
15
|
+
for await (const page of paginator) {
|
|
16
|
+
functions.push(...(page.Functions ?? []).filter((fn) => fn.Runtime?.startsWith("nodejs")));
|
|
17
|
+
}
|
|
18
|
+
return functions;
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/find-v2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "CLI to find resources which call AWS using JavaScript SDK v2",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"types": "dist/cli.d.ts",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@aws-sdk/client-lambda": "^3.942.0",
|
|
10
10
|
"commander": "^14.0.2",
|
|
11
|
-
"node-stream-zip": "^1.15.0"
|
|
11
|
+
"node-stream-zip": "^1.15.0",
|
|
12
|
+
"p-limit": "^7.2.0"
|
|
12
13
|
},
|
|
13
14
|
"devDependencies": {
|
|
14
15
|
"@aws-sdk/client-sts": "^3.946.0",
|