lambda-live-debugger 1.1.3 → 1.2.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.
@@ -11,6 +11,7 @@ let lambdaClient;
11
11
  let iamClient;
12
12
  const inlinePolicyName = 'LambdaLiveDebuggerPolicy';
13
13
  const layerName = 'LambdaLiveDebugger';
14
+ const lldWrapperPath = '/opt/lld-wrapper';
14
15
  /**
15
16
  * Policy document to attach to the Lambda role
16
17
  */
@@ -217,7 +218,14 @@ async function removeLayerFromLambda(functionName) {
217
218
  else {
218
219
  Logger.verbose(`Skipping detaching layer from the function ${functionName}, no layer attached`);
219
220
  }
220
- const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger('xxx', 0);
221
+ const initalExecWraper = environmentVariables.LLD_INITIAL_AWS_LAMBDA_EXEC_WRAPPER;
222
+ const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger({
223
+ // set dummy data, so we just get the list of environment variables
224
+ functionId: 'xxx',
225
+ timeout: 0,
226
+ verbose: true,
227
+ initalExecWraper: 'test',
228
+ });
221
229
  // check if environment variables are set for each property
222
230
  for (const [key] of Object.entries(ddlEnvironmentVariables)) {
223
231
  if (environmentVariables && environmentVariables[key]) {
@@ -231,9 +239,22 @@ async function removeLayerFromLambda(functionName) {
231
239
  //remove environment variables
232
240
  for (const [key] of Object.entries(ddlEnvironmentVariables)) {
233
241
  if (environmentVariables && environmentVariables[key]) {
234
- delete environmentVariables[key];
242
+ if (key === 'AWS_LAMBDA_EXEC_WRAPPER') {
243
+ if (environmentVariables[key] === lldWrapperPath) {
244
+ delete environmentVariables[key];
245
+ }
246
+ else {
247
+ // do not remove the original AWS_LAMBDA_EXEC_WRAPPER that was set before LLD
248
+ }
249
+ }
250
+ else {
251
+ delete environmentVariables[key];
252
+ }
235
253
  }
236
254
  }
255
+ if (initalExecWraper) {
256
+ environmentVariables.AWS_LAMBDA_EXEC_WRAPPER = initalExecWraper;
257
+ }
237
258
  Logger.verbose('New environment variables', JSON.stringify(environmentVariables, null, 2));
238
259
  const updateFunctionConfigurationCommand = new UpdateFunctionConfigurationCommand({
239
260
  FunctionName: functionName,
@@ -314,7 +335,19 @@ async function attachLayerToLambda(functionName, functionId, layerArn) {
314
335
  needToUpdate = true;
315
336
  Logger.verbose('Layer with the wrong version attached to the function');
316
337
  }
317
- const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger(functionId, initialTimeout);
338
+ // support for multiple internal Lambda extensions
339
+ const initalExecWraper = environmentVariables.AWS_LAMBDA_EXEC_WRAPPER !== lldWrapperPath
340
+ ? environmentVariables.AWS_LAMBDA_EXEC_WRAPPER
341
+ : undefined;
342
+ if (initalExecWraper) {
343
+ Logger.warn(`[Function ${functionName}] Another internal Lambda extension is already attached to the function, which might cause unpredictable behavior.`);
344
+ }
345
+ const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger({
346
+ functionId,
347
+ timeout: initialTimeout,
348
+ verbose: Configuration.config.verbose,
349
+ initalExecWraper,
350
+ });
318
351
  // check if environment variables are already set for each property
319
352
  for (const [key, value] of Object.entries(ddlEnvironmentVariables)) {
320
353
  if (!environmentVariables || environmentVariables[key] !== value) {
@@ -386,20 +419,23 @@ async function addPolicyToLambdaRole(functionName) {
386
419
  }
387
420
  /**
388
421
  * Get the environment variables for the Lambda function
389
- * @param functionId
390
- * @param timeout
391
- * @returns
392
422
  */
393
- function getEnvironmentVarablesForDebugger(functionId, timeout) {
394
- return {
423
+ function getEnvironmentVarablesForDebugger({ functionId, timeout, verbose, initalExecWraper, }) {
424
+ const env = {
395
425
  LLD_FUNCTION_ID: functionId,
396
- AWS_LAMBDA_EXEC_WRAPPER: '/opt/lld-wrapper',
397
- NODE_OPTIONS: '--enable-source-maps',
426
+ AWS_LAMBDA_EXEC_WRAPPER: lldWrapperPath,
398
427
  LLD_DEBUGGER_ID: Configuration.config.debuggerId,
399
428
  LLD_INITIAL_TIMEOUT: timeout ? timeout.toString() : '-1', // should never be negative
400
429
  LLD_OBSERVABLE_MODE: Configuration.config.observable ? 'true' : 'false',
401
430
  LLD_OBSERVABLE_INTERVAL: Configuration.config.interval.toString(),
402
431
  };
432
+ if (initalExecWraper) {
433
+ env.LLD_INITIAL_AWS_LAMBDA_EXEC_WRAPPER = initalExecWraper;
434
+ }
435
+ if (verbose) {
436
+ env.LLD_VERBOSE = 'true';
437
+ }
438
+ return env;
403
439
  }
404
440
  /**
405
441
  * Remove the policy from the Lambda role
@@ -80,4 +80,4 @@ async function run() {
80
80
  await LambdaConnection.connect();
81
81
  Logger.log('Debugger started!');
82
82
  }
83
- run().catch(Logger.error);
83
+ run().catch(Logger.error);
package/dist/logger.d.ts CHANGED
@@ -28,6 +28,11 @@ declare function verbose(...args: any[]): void;
28
28
  * @param enabled Whether verbose logging should be enabled
29
29
  */
30
30
  declare function setVerbose(enabled: boolean): void;
31
+ /**
32
+ * Check if verbose logging is enabled
33
+ * @returns Whether verbose logging is enabled
34
+ */
35
+ declare function isVerbose(): boolean;
31
36
  export declare const Logger: {
32
37
  log: typeof log;
33
38
  error: typeof error;
@@ -35,5 +40,6 @@ export declare const Logger: {
35
40
  important: typeof important;
36
41
  verbose: typeof verbose;
37
42
  setVerbose: typeof setVerbose;
43
+ isVerbose: typeof isVerbose;
38
44
  };
39
45
  export {};
package/dist/logger.mjs CHANGED
@@ -55,6 +55,13 @@ function verbose(...args) {
55
55
  function setVerbose(enabled) {
56
56
  verboseEnabled = enabled;
57
57
  }
58
+ /**
59
+ * Check if verbose logging is enabled
60
+ * @returns Whether verbose logging is enabled
61
+ */
62
+ function isVerbose() {
63
+ return verboseEnabled;
64
+ }
58
65
  export const Logger = {
59
66
  log,
60
67
  error,
@@ -62,4 +69,5 @@ export const Logger = {
62
69
  important,
63
70
  verbose,
64
71
  setVerbose,
72
+ isVerbose,
65
73
  };
@@ -14,12 +14,14 @@ async function runInWorker(input) {
14
14
  return new Promise((resolve, reject) => {
15
15
  let worker = workers.get(input.fuctionRequest.workerId);
16
16
  if (!worker) {
17
+ const environment = input.environment;
18
+ addEnableSourceMapsToEnv(environment);
17
19
  worker = startWorker({
18
20
  handler: func.handler ?? 'handler',
19
21
  artifactFile: input.artifactFile,
20
22
  workerId: input.fuctionRequest.workerId,
21
23
  functionId: input.fuctionRequest.functionId,
22
- environment: input.environment,
24
+ environment,
23
25
  verbose: Configuration.config.verbose,
24
26
  });
25
27
  worker.used = false;
@@ -54,6 +56,17 @@ async function runInWorker(input) {
54
56
  });
55
57
  });
56
58
  }
59
+ /**
60
+ * Add NODE_OPTIONS: --enable-source-maps to the environment variables
61
+ * @param environment
62
+ */
63
+ function addEnableSourceMapsToEnv(environment) {
64
+ const nodeOptions = environment.NODE_OPTIONS || '';
65
+ if (!nodeOptions.includes('--enable-source-maps')) {
66
+ environment.NODE_OPTIONS =
67
+ nodeOptions + (nodeOptions ? ' ' : '') + '--enable-source-maps';
68
+ }
69
+ }
57
70
  /**
58
71
  * Start a new Node.js Worker Thread
59
72
  * @param input
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambda-live-debugger",
3
- "version": "1.1.3",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "description": "Debug Lambda functions locally like it is running in the cloud",
6
6
  "repository": {
@@ -41,7 +41,7 @@
41
41
  "lint": "eslint . --fix",
42
42
  "prettier": "prettier . --write",
43
43
  "prepare": "husky",
44
- "add-bang": "sed -i '1s|^|#!/usr/bin/env node\\n|' ./dist/lldebugger.mjs",
44
+ "add-bang": "printf '#!/usr/bin/env node\\n%s' \"$(cat ./dist/lldebugger.mjs)\" > ./dist/lldebugger.mjs.tmp && mv ./dist/lldebugger.mjs.tmp ./dist/lldebugger.mjs",
45
45
  "build": "tsc -p tsconfig.build.json && cp src/nodeWorkerRunner.mjs dist && cp src/frameworks/cdkFrameworkWorker.mjs dist/frameworks && node fix-imports.js && npm run add-bang && npm run bundle-extension",
46
46
  "bundle-extension": "cd src/extension && npm run build && cd ../../",
47
47
  "deploy-github-role": "aws cloudformation deploy --stack-name lld-deploy-role --template-file cloudformation/gitHubDeployRole.yaml --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM --profile lldebugger",