lambda-live-debugger 1.2.0 → 1.2.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/dist/extension/extension.zip +0 -0
- package/dist/extension/nodejs/node_modules/interceptor.js +67 -17
- package/dist/extension/nodejs/node_modules/interceptor.js.map +3 -3
- package/dist/frameworks/samFramework.mjs +8 -5
- package/dist/infraDeploy.mjs +46 -9
- package/dist/lldebugger.mjs +1 -0
- package/dist/logger.d.ts +12 -0
- package/dist/logger.mjs +17 -0
- package/package.json +1 -1
|
@@ -118,9 +118,11 @@ export class SamFramework {
|
|
|
118
118
|
}
|
|
119
119
|
if (!codePath) {
|
|
120
120
|
const fileWithExtension = handlerParts[0];
|
|
121
|
+
const possibleCodePathsTs = `${fileWithExtension}.ts`;
|
|
122
|
+
const possibleCodePathsJs = `${fileWithExtension}.js`;
|
|
121
123
|
const possibleCodePaths = [
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
possibleCodePathsTs,
|
|
125
|
+
possibleCodePathsJs,
|
|
124
126
|
`${fileWithExtension}.cjs`,
|
|
125
127
|
`${fileWithExtension}.mjs`,
|
|
126
128
|
];
|
|
@@ -134,9 +136,10 @@ export class SamFramework {
|
|
|
134
136
|
// ignore, file not found
|
|
135
137
|
}
|
|
136
138
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
if (!codePath) {
|
|
140
|
+
codePath = possibleCodePathsJs;
|
|
141
|
+
Logger.warn(`[Function ${functionName}] Can not find code path for handler: ${handlerFull}. Using fallback: ${codePath}`);
|
|
142
|
+
}
|
|
140
143
|
}
|
|
141
144
|
const packageJsonPath = await findPackageJson(codePath);
|
|
142
145
|
Logger.verbose(`[SAM] package.json path: ${packageJsonPath}`);
|
package/dist/infraDeploy.mjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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,19 +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
|
-
|
|
423
|
+
function getEnvironmentVarablesForDebugger({ functionId, timeout, verbose, initalExecWraper, }) {
|
|
424
|
+
const env = {
|
|
395
425
|
LLD_FUNCTION_ID: functionId,
|
|
396
|
-
AWS_LAMBDA_EXEC_WRAPPER:
|
|
426
|
+
AWS_LAMBDA_EXEC_WRAPPER: lldWrapperPath,
|
|
397
427
|
LLD_DEBUGGER_ID: Configuration.config.debuggerId,
|
|
398
428
|
LLD_INITIAL_TIMEOUT: timeout ? timeout.toString() : '-1', // should never be negative
|
|
399
429
|
LLD_OBSERVABLE_MODE: Configuration.config.observable ? 'true' : 'false',
|
|
400
430
|
LLD_OBSERVABLE_INTERVAL: Configuration.config.interval.toString(),
|
|
401
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;
|
|
402
439
|
}
|
|
403
440
|
/**
|
|
404
441
|
* Remove the policy from the Lambda role
|
package/dist/lldebugger.mjs
CHANGED
|
@@ -79,5 +79,6 @@ async function run() {
|
|
|
79
79
|
FileWatcher.watchForFileChanges(rootFolderForWarchingChanges);
|
|
80
80
|
await LambdaConnection.connect();
|
|
81
81
|
Logger.log('Debugger started!');
|
|
82
|
+
Logger.info(`When you want to stop debugging and return to normal execution, type command 'lld -r' to remove LLD Layer from the functions.`);
|
|
82
83
|
}
|
|
83
84
|
run().catch(Logger.error);
|
package/dist/logger.d.ts
CHANGED
|
@@ -18,6 +18,11 @@ declare function error(...args: any[]): void;
|
|
|
18
18
|
* @param args The arguments to log
|
|
19
19
|
*/
|
|
20
20
|
declare function warn(...args: any[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Log an info message in green
|
|
23
|
+
* @param args The arguments to log
|
|
24
|
+
*/
|
|
25
|
+
declare function info(...args: any[]): void;
|
|
21
26
|
/**
|
|
22
27
|
* Log a verbose message if verbose is enabled. Log the message in grey.
|
|
23
28
|
* @param args The arguments to log
|
|
@@ -28,12 +33,19 @@ declare function verbose(...args: any[]): void;
|
|
|
28
33
|
* @param enabled Whether verbose logging should be enabled
|
|
29
34
|
*/
|
|
30
35
|
declare function setVerbose(enabled: boolean): void;
|
|
36
|
+
/**
|
|
37
|
+
* Check if verbose logging is enabled
|
|
38
|
+
* @returns Whether verbose logging is enabled
|
|
39
|
+
*/
|
|
40
|
+
declare function isVerbose(): boolean;
|
|
31
41
|
export declare const Logger: {
|
|
32
42
|
log: typeof log;
|
|
33
43
|
error: typeof error;
|
|
34
44
|
warn: typeof warn;
|
|
35
45
|
important: typeof important;
|
|
46
|
+
info: typeof info;
|
|
36
47
|
verbose: typeof verbose;
|
|
37
48
|
setVerbose: typeof setVerbose;
|
|
49
|
+
isVerbose: typeof isVerbose;
|
|
38
50
|
};
|
|
39
51
|
export {};
|
package/dist/logger.mjs
CHANGED
|
@@ -38,6 +38,14 @@ function warn(...args) {
|
|
|
38
38
|
args = args.map((arg) => (typeof arg === 'string' ? chalk.yellow(arg) : arg));
|
|
39
39
|
console.warn(...args);
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Log an info message in green
|
|
43
|
+
* @param args The arguments to log
|
|
44
|
+
*/
|
|
45
|
+
function info(...args) {
|
|
46
|
+
args = args.map((arg) => typeof arg === 'string' ? chalk.greenBright(arg) : arg);
|
|
47
|
+
console.info(...args);
|
|
48
|
+
}
|
|
41
49
|
/**
|
|
42
50
|
* Log a verbose message if verbose is enabled. Log the message in grey.
|
|
43
51
|
* @param args The arguments to log
|
|
@@ -55,11 +63,20 @@ function verbose(...args) {
|
|
|
55
63
|
function setVerbose(enabled) {
|
|
56
64
|
verboseEnabled = enabled;
|
|
57
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if verbose logging is enabled
|
|
68
|
+
* @returns Whether verbose logging is enabled
|
|
69
|
+
*/
|
|
70
|
+
function isVerbose() {
|
|
71
|
+
return verboseEnabled;
|
|
72
|
+
}
|
|
58
73
|
export const Logger = {
|
|
59
74
|
log,
|
|
60
75
|
error,
|
|
61
76
|
warn,
|
|
62
77
|
important,
|
|
78
|
+
info,
|
|
63
79
|
verbose,
|
|
64
80
|
setVerbose,
|
|
81
|
+
isVerbose,
|
|
65
82
|
};
|