@aws-sdk/find-v2 0.5.0 → 0.6.0
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
|
@@ -33,17 +33,17 @@ Run `lambda` command to scan Lambda Node.js Functions for JavaScript SDK v2.
|
|
|
33
33
|
|
|
34
34
|
```console
|
|
35
35
|
$ npx @aws-sdk/find-v2 lambda --yes --output table
|
|
36
|
-
|
|
37
|
-
│ FunctionName │ Region │ Runtime │ ContainsAwsSdkJsV2 │
|
|
38
|
-
|
|
39
|
-
│ fn-without-aws-sdk-in-bundle │ us-east-2 │ nodejs24.x │ No. │
|
|
40
|
-
|
|
41
|
-
│ fn-with-aws-sdk-in-bundle │ us-east-2 │ nodejs24.x │ Yes. Bundled in 'index.js' │
|
|
42
|
-
|
|
43
|
-
│ fn-with-aws-sdk-in-package-json-deps │ us-east-2 │ nodejs24.x │ Yes. Defined in dependencies of 'package.json' │
|
|
44
|
-
|
|
45
|
-
│ fn-without-aws-sdk-in-package-json-deps │ us-east-2 │ nodejs24.x │ No. │
|
|
46
|
-
|
|
36
|
+
┌─────────────────────────────────────────┬───────────┬────────────┬────────────┬────────────────────────────────────────────────┐
|
|
37
|
+
│ FunctionName │ Region │ Runtime │ SdkVersion │ ContainsAwsSdkJsV2 │
|
|
38
|
+
├─────────────────────────────────────────┼───────────┼────────────┼────────────┼────────────────────────────────────────────────┤
|
|
39
|
+
│ fn-without-aws-sdk-in-bundle │ us-east-2 │ nodejs24.x │ >=2.0.0 │ No. │
|
|
40
|
+
├─────────────────────────────────────────┼───────────┼────────────┼────────────┼────────────────────────────────────────────────┤
|
|
41
|
+
│ fn-with-aws-sdk-in-bundle │ us-east-2 │ nodejs24.x │ >=2.0.0 │ Yes. Bundled in 'index.js' │
|
|
42
|
+
├─────────────────────────────────────────┼───────────┼────────────┼────────────┼────────────────────────────────────────────────┤
|
|
43
|
+
│ fn-with-aws-sdk-in-package-json-deps │ us-east-2 │ nodejs24.x │ >=2.0.0 │ Yes. Defined in dependencies of 'package.json' │
|
|
44
|
+
├─────────────────────────────────────────┼───────────┼────────────┼────────────┼────────────────────────────────────────────────┤
|
|
45
|
+
│ fn-without-aws-sdk-in-package-json-deps │ us-east-2 │ nodejs24.x │ >=2.0.0 │ No. │
|
|
46
|
+
└─────────────────────────────────────────┴───────────┴────────────┴────────────┴────────────────────────────────────────────────┘
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
This script requires AWS Managed Policy [AWSLambda_ReadOnlyAccess][].
|
package/dist/cli.js
CHANGED
|
@@ -29,6 +29,15 @@ export const createProgram = () => {
|
|
|
29
29
|
}
|
|
30
30
|
return value;
|
|
31
31
|
}, ">=20")
|
|
32
|
+
.option("--sdk <semver>", "Semver range string to check for AWS SDK for JavaScript v2", (value) => {
|
|
33
|
+
try {
|
|
34
|
+
satisfies("0", value);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new Error(`Invalid semver range: ${value}`);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}, ">=2.0.0")
|
|
32
41
|
.option("--region <region>", "AWS region to scan")
|
|
33
42
|
.option("--profile <profile>", "AWS profile to use")
|
|
34
43
|
.addOption(new Option("-o, --output <output>", "Output format")
|
|
@@ -6,7 +6,7 @@ import { getLambdaFunctionScanOutput } from "./utils/getLambdaFunctionScanOutput
|
|
|
6
6
|
import { getLambdaNodeJsMatchingVersions } from "./utils/getLambdaNodeJsMatchingVersions.js";
|
|
7
7
|
import { LambdaCommandOutputType, printLambdaCommandOutput, } from "./utils/printLambdaCommandOutput.js";
|
|
8
8
|
export const scanLambdaFunctions = async (options) => {
|
|
9
|
-
const { yes, node, region, profile, output, jobs } = options;
|
|
9
|
+
const { yes, node, sdk, region, profile, output, jobs } = options;
|
|
10
10
|
const client = new Lambda({
|
|
11
11
|
...(region && { region }),
|
|
12
12
|
...(profile && { profile }),
|
|
@@ -43,6 +43,7 @@ export const scanLambdaFunctions = async (options) => {
|
|
|
43
43
|
functionName: fn.FunctionName,
|
|
44
44
|
region: clientRegion,
|
|
45
45
|
runtime: fn.Runtime,
|
|
46
|
+
sdkVersionRange: sdk,
|
|
46
47
|
}))));
|
|
47
48
|
printLambdaCommandOutput(scanOutput, output);
|
|
48
49
|
};
|
|
@@ -1,14 +1,27 @@
|
|
|
1
|
+
import { satisfies } from "compare-versions";
|
|
1
2
|
import { downloadFile } from "./downloadFile.js";
|
|
2
3
|
import { getLambdaFunctionContents, } from "./getLambdaFunctionContents.js";
|
|
3
4
|
import { hasSdkV2InBundle } from "./hasSdkV2InBundle.js";
|
|
4
5
|
import { rm } from "node:fs/promises";
|
|
5
6
|
import { tmpdir } from "node:os";
|
|
6
7
|
import { join } from "node:path";
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Scans a Lambda function to detect AWS SDK for JavaScript v2 usage.
|
|
10
|
+
*
|
|
11
|
+
* Downloads the function code, extracts it, and checks for v2 SDK in:
|
|
12
|
+
* 1. package.json dependencies
|
|
13
|
+
* 2. Bundled index file
|
|
14
|
+
*
|
|
15
|
+
* @param client - AWS Lambda client instance
|
|
16
|
+
* @param options - Scan configuration options
|
|
17
|
+
* @returns Scan results including SDK v2 detection status and location
|
|
18
|
+
*/
|
|
19
|
+
export const getLambdaFunctionScanOutput = async (client, { functionName, region, runtime, sdkVersionRange }) => {
|
|
8
20
|
const output = {
|
|
9
21
|
FunctionName: functionName,
|
|
10
22
|
Region: region,
|
|
11
23
|
Runtime: runtime,
|
|
24
|
+
SdkVersion: sdkVersionRange,
|
|
12
25
|
ContainsAwsSdkJsV2: null,
|
|
13
26
|
};
|
|
14
27
|
const response = await client.getFunction({ FunctionName: functionName });
|
|
@@ -23,10 +36,9 @@ export const getLambdaFunctionScanOutput = async (client, { functionName, region
|
|
|
23
36
|
lambdaFunctionContents = await getLambdaFunctionContents(zipPath);
|
|
24
37
|
}
|
|
25
38
|
catch (error) {
|
|
39
|
+
const errorPrefix = "Error downloading or reading Lambda function code";
|
|
26
40
|
output.AwsSdkJsV2Error =
|
|
27
|
-
error instanceof Error
|
|
28
|
-
? `Error downloading or reading Lambda function code: ${error.message}`
|
|
29
|
-
: "Error downloading or reading Lambda function code.";
|
|
41
|
+
error instanceof Error ? `${errorPrefix}: ${error.message}` : errorPrefix;
|
|
30
42
|
return output;
|
|
31
43
|
}
|
|
32
44
|
finally {
|
|
@@ -40,6 +52,17 @@ export const getLambdaFunctionScanOutput = async (client, { functionName, region
|
|
|
40
52
|
const packageJson = JSON.parse(packageJsonContent);
|
|
41
53
|
const dependencies = packageJson.dependencies || {};
|
|
42
54
|
if ("aws-sdk" in dependencies) {
|
|
55
|
+
try {
|
|
56
|
+
if (!satisfies(dependencies["aws-sdk"], sdkVersionRange)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const errorPrefix = `Error checking version range '${sdkVersionRange}' for aws-sdk@${dependencies["aws-sdk"]} in '${packageJsonPath}'`;
|
|
62
|
+
output.AwsSdkJsV2Error =
|
|
63
|
+
error instanceof Error ? `${errorPrefix}: ${error.message}` : errorPrefix;
|
|
64
|
+
return output;
|
|
65
|
+
}
|
|
43
66
|
output.ContainsAwsSdkJsV2 = true;
|
|
44
67
|
output.AwsSdkJsV2Location = `Defined in dependencies of '${packageJsonPath}'`;
|
|
45
68
|
return output;
|
|
@@ -54,10 +77,20 @@ export const getLambdaFunctionScanOutput = async (client, { functionName, region
|
|
|
54
77
|
}
|
|
55
78
|
}
|
|
56
79
|
// Check for code of "aws-sdk" in bundle, if not found in package.json dependencies.
|
|
57
|
-
if (bundleFile
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
80
|
+
if (bundleFile) {
|
|
81
|
+
try {
|
|
82
|
+
if (hasSdkV2InBundle(bundleFile.content, sdkVersionRange)) {
|
|
83
|
+
output.ContainsAwsSdkJsV2 = true;
|
|
84
|
+
output.AwsSdkJsV2Location = `Bundled in '${bundleFile.path}'`;
|
|
85
|
+
return output;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const errorPrefix = `Error reading bundle '${bundleFile.path}' for aws-sdk@${sdkVersionRange}`;
|
|
90
|
+
output.AwsSdkJsV2Error =
|
|
91
|
+
error instanceof Error ? `${errorPrefix}: ${error.message}` : errorPrefix;
|
|
92
|
+
return output;
|
|
93
|
+
}
|
|
61
94
|
}
|
|
62
95
|
// "aws-sdk" dependency/code not found.
|
|
63
96
|
output.ContainsAwsSdkJsV2 = false;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { satisfies } from "compare-versions";
|
|
1
2
|
const AWS_SDK_ENV_VARS = [
|
|
2
3
|
"AWS_CONFIG_FILE",
|
|
3
4
|
// "AWS_CONTAINER_AUTHORIZATION_TOKEN", // Tree shaken by esbuild
|
|
@@ -32,13 +33,23 @@ const AWS_SDK_ENV_VARS = [
|
|
|
32
33
|
* Checks if AWS SDK v2 is present in the provided bundle content by looking for specific environment variables.
|
|
33
34
|
*
|
|
34
35
|
* @param bundleContent - The string content of the bundle to check.
|
|
36
|
+
* @param sdkVersionRange - Semver range string to check for AWS SDK for JavaScript v2
|
|
35
37
|
* @returns boolean - Returns true if all AWS SDK v2 environment variables are found in the bundle content, false otherwise.
|
|
36
38
|
*/
|
|
37
|
-
export const hasSdkV2InBundle = (bundleContent) => {
|
|
39
|
+
export const hasSdkV2InBundle = (bundleContent, sdkVersionRange) => {
|
|
38
40
|
for (const envVar of AWS_SDK_ENV_VARS) {
|
|
39
41
|
if (!bundleContent.includes(envVar)) {
|
|
40
42
|
return false;
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
|
-
|
|
45
|
+
// Get version number from `VERSION:'2.X.Y'` or `VERSION: '2.X.Y'`, including double quotes and backticks.
|
|
46
|
+
const matches = bundleContent.match(/VERSION:\s*(['"`])(2\.\d+\.\d+)\1/);
|
|
47
|
+
if (matches && matches[2]) {
|
|
48
|
+
const version = matches[2];
|
|
49
|
+
// If version is in the specified range, return true
|
|
50
|
+
if (satisfies(version, sdkVersionRange)) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
44
55
|
};
|
|
@@ -13,7 +13,7 @@ export const printLambdaCommandOutput = (output, outputType) => {
|
|
|
13
13
|
}
|
|
14
14
|
// Output as table
|
|
15
15
|
const table = new Table({
|
|
16
|
-
head: ["FunctionName", "Region", "Runtime", "ContainsAwsSdkJsV2"],
|
|
16
|
+
head: ["FunctionName", "Region", "Runtime", "SdkVersion", "ContainsAwsSdkJsV2"],
|
|
17
17
|
style: { head: ["bold"] },
|
|
18
18
|
});
|
|
19
19
|
for (const scanOutput of output) {
|
|
@@ -28,7 +28,13 @@ export const printLambdaCommandOutput = (output, outputType) => {
|
|
|
28
28
|
if (scanOutput.AwsSdkJsV2Location !== undefined) {
|
|
29
29
|
notes += ` ${scanOutput.AwsSdkJsV2Location}`;
|
|
30
30
|
}
|
|
31
|
-
table.push([
|
|
31
|
+
table.push([
|
|
32
|
+
scanOutput.FunctionName,
|
|
33
|
+
scanOutput.Region,
|
|
34
|
+
scanOutput.Runtime,
|
|
35
|
+
scanOutput.SdkVersion,
|
|
36
|
+
notes,
|
|
37
|
+
]);
|
|
32
38
|
}
|
|
33
39
|
console.log(table.toString());
|
|
34
40
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/find-v2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"@tsconfig/node-ts": "^23.6.2",
|
|
26
26
|
"@tsconfig/node20": "^20.1.8",
|
|
27
27
|
"@types/node": "^20.14.8",
|
|
28
|
-
"aws-sdk": "
|
|
28
|
+
"aws-sdk": "2.1693.0",
|
|
29
29
|
"esbuild": "~0.27.1",
|
|
30
|
-
"oxfmt": "^0.
|
|
30
|
+
"oxfmt": "^0.21.0",
|
|
31
31
|
"oxlint": "^1.33.0",
|
|
32
32
|
"parcel": "^2.16.3",
|
|
33
|
-
"rolldown": "1.0.0-beta.
|
|
33
|
+
"rolldown": "1.0.0-beta.58",
|
|
34
34
|
"rollup": "^4.53.3",
|
|
35
35
|
"typescript": "^5.9.3",
|
|
36
36
|
"vitest": "^4.0.15",
|