@aws-sdk/find-v2 0.4.0 → 0.4.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.
package/README.md CHANGED
@@ -43,13 +43,13 @@ $ npx @aws-sdk/find-v2 lambda --yes
43
43
  "FunctionName": "fn-with-aws-sdk-in-bundle",
44
44
  "Region": "us-east-2",
45
45
  "ContainsAwsSdkJsV2": true,
46
- "AwsSdkJsV2Location": "Bundled in index file."
46
+ "AwsSdkJsV2Location": "Bundled in 'index.js'"
47
47
  },
48
48
  {
49
49
  "FunctionName": "fn-with-aws-sdk-in-package-json-deps",
50
50
  "Region": "us-east-2",
51
51
  "ContainsAwsSdkJsV2": true,
52
- "AwsSdkJsV2Location": "Defined in package.json dependencies."
52
+ "AwsSdkJsV2Location": "Defined in dependencies of 'package.json'"
53
53
  },
54
54
  {
55
55
  "FunctionName": "fn-without-aws-sdk-in-package-json-deps",
package/dist/cli.js CHANGED
@@ -17,8 +17,9 @@ export const createProgram = () => {
17
17
  program
18
18
  .command("lambda")
19
19
  .description("Scans Lambda Node.js Functions for JavaScript SDK v2")
20
- .option("-r, --region <region>", "AWS region to scan")
21
20
  .option("-y, --yes", "answer yes for all prompts")
21
+ .option("-r, --region <region>", "AWS region to scan")
22
+ .option("-p, --profile <profile>", "AWS profile to use")
22
23
  .option("-j, --jobs <count>", "number of parallel jobs", (value) => {
23
24
  const trimmed = value.trim();
24
25
  if (!/^\d+$/.test(trimmed)) {
@@ -31,32 +31,31 @@ export const getLambdaFunctionScanOutput = async (client, { functionName, region
31
31
  finally {
32
32
  await rm(zipPath, { force: true });
33
33
  }
34
- const { packageJsonContents, bundleContent } = lambdaFunctionContents;
34
+ const { packageJsonFiles, bundleFile } = lambdaFunctionContents;
35
35
  // Search for "aws-sdk" in package.json dependencies if present.
36
- if (packageJsonContents && packageJsonContents.length > 0) {
37
- for (const packageJsonContent of packageJsonContents) {
36
+ if (packageJsonFiles && packageJsonFiles.length > 0) {
37
+ for (const { path: packageJsonPath, content: packageJsonContent } of packageJsonFiles) {
38
38
  try {
39
39
  const packageJson = JSON.parse(packageJsonContent);
40
40
  const dependencies = packageJson.dependencies || {};
41
41
  if ("aws-sdk" in dependencies) {
42
42
  output.ContainsAwsSdkJsV2 = true;
43
- output.AwsSdkJsV2Location = "Defined in package.json dependencies.";
43
+ output.AwsSdkJsV2Location = `Defined in dependencies of '${packageJsonPath}'`;
44
44
  return output;
45
45
  }
46
46
  }
47
47
  catch (error) {
48
+ const errorPrefix = `Error parsing '${packageJsonPath}'`;
48
49
  output.AwsSdkJsV2Error =
49
- error instanceof Error
50
- ? `Error parsing package.json: ${error.message}`
51
- : "Error parsing package.json";
50
+ error instanceof Error ? `${errorPrefix}: ${error.message}` : errorPrefix;
52
51
  return output;
53
52
  }
54
53
  }
55
54
  }
56
55
  // Check for code of "aws-sdk" in bundle, if not found in package.json dependencies.
57
- if (bundleContent && hasSdkV2InBundle(bundleContent)) {
56
+ if (bundleFile && hasSdkV2InBundle(bundleFile.content)) {
58
57
  output.ContainsAwsSdkJsV2 = true;
59
- output.AwsSdkJsV2Location = "Bundled in index file.";
58
+ output.AwsSdkJsV2Location = `Bundled in '${bundleFile.path}'`;
60
59
  return output;
61
60
  }
62
61
  // "aws-sdk" dependency/code not found.
@@ -4,8 +4,11 @@ import { getLambdaFunctionScanOutput } from "./getLambdaFunctionScanOutput.js";
4
4
  import { getDownloadConfirmation } from "./utils/getDownloadConfirmation.js";
5
5
  import { getLambdaFunctions } from "./utils/getLambdaFunctions.js";
6
6
  export const scanLambdaFunctions = async (options = {}) => {
7
- const { region, yes, jobs } = options;
8
- const client = new Lambda({ region });
7
+ const { region, yes, jobs, profile } = options;
8
+ const client = new Lambda({
9
+ ...(region && { region }),
10
+ ...(profile && { profile }),
11
+ });
9
12
  const functions = await getLambdaFunctions(client);
10
13
  const functionCount = functions.length;
11
14
  const concurrency = Math.min(functionCount, jobs || 1);
@@ -10,7 +10,7 @@ const PACKAGE_JSON_FILENAME = "package.json";
10
10
  */
11
11
  export const getLambdaFunctionContents = async (zipPath) => {
12
12
  const zip = new StreamZip.async({ file: zipPath });
13
- const packageJsonContents = [];
13
+ const packageJsonFiles = [];
14
14
  let zipEntries = {};
15
15
  try {
16
16
  zipEntries = await zip.entries();
@@ -31,16 +31,19 @@ export const getLambdaFunctionContents = async (zipPath) => {
31
31
  continue;
32
32
  try {
33
33
  const packageJsonContent = await zip.entryData(zipEntry.name);
34
- packageJsonContents.push(packageJsonContent.toString());
34
+ packageJsonFiles.push({
35
+ path: zipEntry.name,
36
+ content: packageJsonContent.toString(),
37
+ });
35
38
  }
36
39
  catch {
37
40
  // Continue without adding package.json file, if entry data can't be read.
38
41
  // ToDo: add warning when logging is supported in future.
39
42
  }
40
43
  }
41
- if (packageJsonContents.length !== 0) {
44
+ if (packageJsonFiles.length !== 0) {
42
45
  await zip.close();
43
- return { packageJsonContents };
46
+ return { packageJsonFiles };
44
47
  }
45
48
  for (const path of ["index.js", "index.mjs", "index.cjs"]) {
46
49
  if (!zipEntries[path])
@@ -50,7 +53,12 @@ export const getLambdaFunctionContents = async (zipPath) => {
50
53
  try {
51
54
  const bundleContent = await zip.entryData(path);
52
55
  await zip.close();
53
- return { bundleContent: bundleContent.toString() };
56
+ return {
57
+ bundleFile: {
58
+ path,
59
+ content: bundleContent.toString(),
60
+ },
61
+ };
54
62
  }
55
63
  catch {
56
64
  // Continue processing next index file, if entry data can't be read.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/find-v2",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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",