lambda-live-debugger 1.1.2 → 1.2.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.
@@ -74,10 +74,10 @@ export default defineConfig({
74
74
  { text: 'CLI Parameters', link: '#cli-parameters' },
75
75
  { text: 'Configuration file', link: '#configuration-file' },
76
76
  { text: 'Debugging', link: '#debugging' },
77
+ { text: 'Removing', link: '#removing' },
77
78
  { text: 'Development Process', link: '#development-process' },
78
79
  { text: 'Observability Mode', link: '#observability-mode' },
79
80
  { text: 'Monorepo', link: '#monorepo-setup' },
80
- { text: 'Removing', link: '#removing' },
81
81
  ],
82
82
  },
83
83
  {
package/README.md CHANGED
@@ -167,21 +167,9 @@ Now, you have to press F5 or press Run -> Start Debugging, and you can set break
167
167
 
168
168
  For other tools, please send documentation to include here. WebStorm instructions are especially needed.
169
169
 
170
- ## Development Process
171
-
172
- Since you deploy code to a real AWS account, it's best to have a dedicated environment only for yourself. It could be your personal environment or an environment created for a feature. That is [common practice when developing serverless systems](https://theburningmonk.com/2019/09/why-you-should-use-temporary-stacks-when-you-do-serverless/). If that's not feasible due to organizational or technical reasons, use Observability Mode.
173
-
174
- ## Observability Mode
175
-
176
- In Observability Mode, Lambda Live Debugger intercepts requests and sends them to your computer without waiting for a response. The Lambda continues as usual. The response from your machine is ignored. This mode can be used in the development, testing, or even, if you are adventurous, production environment. It samples requests every 3 seconds by default (configurable with an `interval` setting) to avoid overloading the system.
177
-
178
- ## Monorepo Setup
179
-
180
- Set the `subfolder` parameter if your framework is in a subfolder.
181
-
182
170
  ## Removing
183
171
 
184
- To remove Lambda Live Debugger from your AWS account
172
+ When you no longer want to debug and want Lambda to execute the code deployed to the cloud, you need to remove the Lambda Live Debugger:
185
173
 
186
174
  ```
187
175
  lld -r
@@ -195,6 +183,18 @@ To also remove the Layer:
195
183
  lld -r=all
196
184
  ```
197
185
 
186
+ ## Development Process
187
+
188
+ Since you deploy code to a real AWS account, it's best to have a dedicated environment only for yourself. It could be your personal environment or an environment created for a feature. That is [common practice when developing serverless systems](https://theburningmonk.com/2019/09/why-you-should-use-temporary-stacks-when-you-do-serverless/). If that's not feasible due to organizational or technical reasons, use Observability Mode.
189
+
190
+ ## Observability Mode
191
+
192
+ In Observability Mode, Lambda Live Debugger intercepts requests and sends them to your computer without waiting for a response. The Lambda continues as usual. The response from your machine is ignored. This mode can be used in the development, testing, or even, if you are adventurous, production environment. It samples requests every 3 seconds by default (configurable with an `interval` setting) to avoid overloading the system.
193
+
194
+ ## Monorepo Setup
195
+
196
+ Set the `subfolder` parameter if your framework is in a subfolder.
197
+
198
198
  ## Frameworks
199
199
 
200
200
  ### AWS CDK v2
Binary file
@@ -21,6 +21,6 @@ export declare class SlsFramework implements IFramework {
21
21
  * @returns Lambda functions
22
22
  */
23
23
  getLambdas(config: LldConfigBase): Promise<LambdaResource[]>;
24
- protected getEsBuildOptions(serverless: Serverless): EsBuildOptions | undefined;
24
+ protected getEsBuildOptions(serverless: Serverless, config: LldConfigBase): EsBuildOptions | undefined;
25
25
  }
26
26
  export declare const slsFramework: SlsFramework;
@@ -47,6 +47,9 @@ export class SlsFramework {
47
47
  process.argv = [];
48
48
  let resolveConfigurationPath;
49
49
  let readConfiguration;
50
+ let resolveVariables;
51
+ let resolveVariablesMeta;
52
+ let sources;
50
53
  let Serverless;
51
54
  try {
52
55
  // lazy load modules
@@ -56,11 +59,43 @@ export class SlsFramework {
56
59
  readConfiguration = (await import(
57
60
  //@ts-ignore
58
61
  'serverless/lib/configuration/read.js')).default;
62
+ resolveVariables = (await import(
63
+ //@ts-ignore
64
+ 'serverless/lib/configuration/variables/resolve.js')).default;
65
+ resolveVariablesMeta = (await import(
66
+ //@ts-ignore
67
+ 'serverless/lib/configuration/variables/resolve-meta.js')).default;
68
+ const env = await import(
69
+ //@ts-ignore
70
+ 'serverless/lib/configuration/variables/sources/env.js');
71
+ const file = await import(
72
+ //@ts-ignore
73
+ 'serverless/lib/configuration/variables/sources/file.js');
74
+ const opt = await import(
75
+ //@ts-ignore
76
+ 'serverless/lib/configuration/variables/sources/opt.js');
77
+ const self = await import(
78
+ //@ts-ignore
79
+ 'serverless/lib/configuration/variables/sources/self.js');
80
+ const strToBool = await import(
81
+ //@ts-ignore
82
+ 'serverless/lib/configuration/variables/sources/str-to-bool.js');
83
+ const sls = await import(
84
+ //@ts-ignores
85
+ 'serverless/lib/configuration/variables/sources/instance-dependent/get-sls.js');
86
+ sources = {
87
+ env: env.default,
88
+ file: file.default,
89
+ opt: opt.default,
90
+ self: self.default,
91
+ strToBool: strToBool.default,
92
+ sls: sls.default(),
93
+ };
59
94
  Serverless = (await import('serverless')).default;
60
95
  }
61
96
  catch (error) {
62
97
  Logger.error('Error loading serverless modules', error);
63
- Logger.log('If you are running Lambda Live Debugger from a global installation, install Serverless Framework globally as well.');
98
+ Logger.log('If you are running Lambda Live Debugger from a global installation, install Serverless Framework globally as well. If you are using monorepo, install Serverless Framework also in the project root folder.');
64
99
  throw new Error(`Error loading serverless modules. ${error.message}`, {
65
100
  cause: error,
66
101
  });
@@ -83,7 +118,15 @@ export class SlsFramework {
83
118
  if (config.profile) {
84
119
  options.profile = config.profile;
85
120
  }
86
- const variablesMeta = {};
121
+ const variablesMeta = resolveVariablesMeta(configuration);
122
+ await resolveVariables({
123
+ serviceDir,
124
+ configuration,
125
+ variablesMeta,
126
+ sources,
127
+ options,
128
+ fulfilledSources: new Set(),
129
+ });
87
130
  let serverless;
88
131
  try {
89
132
  serverless = new Serverless({
@@ -117,7 +160,7 @@ export class SlsFramework {
117
160
  });
118
161
  }
119
162
  const lambdasDiscovered = [];
120
- const esBuildOptions = this.getEsBuildOptions(serverless);
163
+ const esBuildOptions = this.getEsBuildOptions(serverless, config);
121
164
  const lambdas = serverless.service.functions;
122
165
  Logger.verbose(`[SLS] Found Lambdas:`, JSON.stringify(lambdas, null, 2));
123
166
  for (const func in lambdas) {
@@ -165,7 +208,8 @@ export class SlsFramework {
165
208
  }
166
209
  return lambdasDiscovered;
167
210
  }
168
- getEsBuildOptions(serverless) {
211
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
212
+ getEsBuildOptions(serverless, config) {
169
213
  // 1) Get from from LLD specific options in custom.lldEsBuild
170
214
  let esBuildOptions = serverless.service.custom?.lldEsBuild;
171
215
  // 2) Get from serverless-esbuild plugin
@@ -189,7 +233,7 @@ export class SlsFramework {
189
233
  const settings = serverless.service.custom?.serverlessPluginTypescript;
190
234
  if (settings) {
191
235
  esBuildOptions = {
192
- tsconfig: settings.tsConfigFileLocation,
236
+ tsconfig: path.resolve(settings.tsConfigFileLocation),
193
237
  };
194
238
  }
195
239
  }
@@ -394,7 +394,6 @@ function getEnvironmentVarablesForDebugger(functionId, timeout) {
394
394
  return {
395
395
  LLD_FUNCTION_ID: functionId,
396
396
  AWS_LAMBDA_EXEC_WRAPPER: '/opt/lld-wrapper',
397
- NODE_OPTIONS: '--enable-source-maps',
398
397
  LLD_DEBUGGER_ID: Configuration.config.debuggerId,
399
398
  LLD_INITIAL_TIMEOUT: timeout ? timeout.toString() : '-1', // should never be negative
400
399
  LLD_OBSERVABLE_MODE: Configuration.config.observable ? 'true' : 'false',
@@ -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);
@@ -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.2",
3
+ "version": "1.2.0",
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",