@aws-sdk/find-v2 0.4.2 → 0.4.3
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/README.md
CHANGED
|
@@ -32,31 +32,18 @@ Commands:
|
|
|
32
32
|
Run `lambda` command to scan Lambda Node.js Functions for JavaScript SDK v2.
|
|
33
33
|
|
|
34
34
|
```console
|
|
35
|
-
$ npx @aws-sdk/find-v2 lambda --yes
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
"FunctionName": "fn-with-aws-sdk-in-package-json-deps",
|
|
50
|
-
"Region": "us-east-2",
|
|
51
|
-
"ContainsAwsSdkJsV2": true,
|
|
52
|
-
"AwsSdkJsV2Location": "Defined in dependencies of 'package.json'"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"FunctionName": "fn-without-aws-sdk-in-package-json-deps",
|
|
56
|
-
"Region": "us-east-2",
|
|
57
|
-
"ContainsAwsSdkJsV2": false
|
|
58
|
-
}
|
|
59
|
-
]
|
|
35
|
+
$ npx @aws-sdk/find-v2 lambda --yes --output table
|
|
36
|
+
┌─────────────────────────────────────────┬───────────┬────────────────────────────────────────────────┐
|
|
37
|
+
│ FunctionName │ Region │ ContainsAwsSdkJsV2 │
|
|
38
|
+
├─────────────────────────────────────────┼───────────┼────────────────────────────────────────────────┤
|
|
39
|
+
│ fn-without-aws-sdk-in-bundle │ us-east-2 │ No. │
|
|
40
|
+
├─────────────────────────────────────────┼───────────┼────────────────────────────────────────────────┤
|
|
41
|
+
│ fn-with-aws-sdk-in-bundle │ us-east-2 │ Yes. Bundled in 'index.js' │
|
|
42
|
+
├─────────────────────────────────────────┼───────────┼────────────────────────────────────────────────┤
|
|
43
|
+
│ fn-with-aws-sdk-in-package-json-deps │ us-east-2 │ Yes. Defined in dependencies of 'package.json' │
|
|
44
|
+
├─────────────────────────────────────────┼───────────┼────────────────────────────────────────────────┤
|
|
45
|
+
│ fn-without-aws-sdk-in-package-json-deps │ us-east-2 │ No. │
|
|
46
|
+
└─────────────────────────────────────────┴───────────┴────────────────────────────────────────────────┘
|
|
60
47
|
```
|
|
61
48
|
|
|
62
49
|
This script requires AWS Managed Policy [AWSLambda_ReadOnlyAccess][].
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
1
|
+
import { Command, Option } from "commander";
|
|
2
2
|
import { cpus } from "node:os";
|
|
3
3
|
import packageJson from "../package.json" with { type: "json" };
|
|
4
4
|
import { scanLambdaFunctions } from "./scanLambdaFunctions.js";
|
|
5
|
+
import { LambdaCommandOutputType } from "./utils/printLambdaCommandOutput.js";
|
|
5
6
|
/**
|
|
6
7
|
* Creates and configures the CLI program with available commands.
|
|
7
8
|
*
|
|
@@ -17,9 +18,12 @@ export const createProgram = () => {
|
|
|
17
18
|
program
|
|
18
19
|
.command("lambda")
|
|
19
20
|
.description("Scans Lambda Node.js Functions for JavaScript SDK v2")
|
|
20
|
-
.option("-y, --yes", "answer yes for all prompts")
|
|
21
|
+
.option("-y, --yes", "answer yes for all prompts", false)
|
|
21
22
|
.option("-r, --region <region>", "AWS region to scan")
|
|
22
23
|
.option("-p, --profile <profile>", "AWS profile to use")
|
|
24
|
+
.addOption(new Option("-o, --output <output>", "Output format")
|
|
25
|
+
.choices(Object.values(LambdaCommandOutputType))
|
|
26
|
+
.default(LambdaCommandOutputType.json))
|
|
23
27
|
.option("-j, --jobs <count>", "number of parallel jobs", (value) => {
|
|
24
28
|
const trimmed = value.trim();
|
|
25
29
|
if (!/^\d+$/.test(trimmed)) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Lambda } from "@aws-sdk/client-lambda";
|
|
2
2
|
import pLimit from "p-limit";
|
|
3
|
-
import { getLambdaFunctionScanOutput } from "./getLambdaFunctionScanOutput.js";
|
|
4
3
|
import { getDownloadConfirmation } from "./utils/getDownloadConfirmation.js";
|
|
5
4
|
import { getLambdaFunctions } from "./utils/getLambdaFunctions.js";
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { getLambdaFunctionScanOutput } from "./utils/getLambdaFunctionScanOutput.js";
|
|
6
|
+
import { LambdaCommandOutputType, printLambdaCommandOutput, } from "./utils/printLambdaCommandOutput.js";
|
|
7
|
+
export const scanLambdaFunctions = async (options) => {
|
|
8
|
+
const { yes, region, profile, output, jobs } = options;
|
|
8
9
|
const client = new Lambda({
|
|
9
10
|
...(region && { region }),
|
|
10
11
|
...(profile && { profile }),
|
|
@@ -32,9 +33,9 @@ export const scanLambdaFunctions = async (options = {}) => {
|
|
|
32
33
|
}
|
|
33
34
|
const clientRegion = await client.config.region();
|
|
34
35
|
const limit = pLimit(concurrency);
|
|
35
|
-
const
|
|
36
|
+
const scanOutput = await Promise.all(functions.map((fn) => limit(() => getLambdaFunctionScanOutput(client, {
|
|
36
37
|
functionName: fn.FunctionName,
|
|
37
38
|
region: clientRegion,
|
|
38
39
|
}))));
|
|
39
|
-
|
|
40
|
+
printLambdaCommandOutput(scanOutput, output);
|
|
40
41
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { downloadFile } from "./
|
|
2
|
-
import { getLambdaFunctionContents, } from "./
|
|
3
|
-
import { hasSdkV2InBundle } from "./
|
|
1
|
+
import { downloadFile } from "./downloadFile.js";
|
|
2
|
+
import { getLambdaFunctionContents, } from "./getLambdaFunctionContents.js";
|
|
3
|
+
import { hasSdkV2InBundle } from "./hasSdkV2InBundle.js";
|
|
4
4
|
import { rm } from "node:fs/promises";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import { join } from "node:path";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Table from "cli-table3";
|
|
2
|
+
export const LambdaCommandOutputType = {
|
|
3
|
+
// prints output as JSON
|
|
4
|
+
json: "json",
|
|
5
|
+
// prints human-readable representation in a table
|
|
6
|
+
table: "table",
|
|
7
|
+
};
|
|
8
|
+
export const printLambdaCommandOutput = (output, outputType) => {
|
|
9
|
+
// Output as JSON
|
|
10
|
+
if (outputType === LambdaCommandOutputType.json) {
|
|
11
|
+
console.log(JSON.stringify(output, null, 2));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
// Output as table
|
|
15
|
+
const table = new Table({
|
|
16
|
+
head: ["FunctionName", "Region", "ContainsAwsSdkJsV2"],
|
|
17
|
+
style: { head: ["bold"] },
|
|
18
|
+
});
|
|
19
|
+
for (const scanOutput of output) {
|
|
20
|
+
let notes = scanOutput.ContainsAwsSdkJsV2 === null
|
|
21
|
+
? "N/A."
|
|
22
|
+
: scanOutput.ContainsAwsSdkJsV2
|
|
23
|
+
? "Yes."
|
|
24
|
+
: "No.";
|
|
25
|
+
if (scanOutput.AwsSdkJsV2Error !== undefined) {
|
|
26
|
+
notes += ` ${scanOutput.AwsSdkJsV2Error}`;
|
|
27
|
+
}
|
|
28
|
+
if (scanOutput.AwsSdkJsV2Location !== undefined) {
|
|
29
|
+
notes += ` ${scanOutput.AwsSdkJsV2Location}`;
|
|
30
|
+
}
|
|
31
|
+
table.push([scanOutput.FunctionName, scanOutput.Region, notes]);
|
|
32
|
+
}
|
|
33
|
+
console.log(table.toString());
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/find-v2",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
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",
|
|
7
7
|
"bin": "bin/@aws-sdk/find-v2",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@aws-sdk/client-lambda": "^3.942.0",
|
|
10
|
+
"cli-table3": "^0.6.5",
|
|
10
11
|
"commander": "^14.0.2",
|
|
11
12
|
"node-stream-zip": "^1.15.0",
|
|
12
13
|
"p-limit": "^7.2.0"
|