Skip to content

Commit e4cbd2d

Browse files
feat: Speed up and clean up code for adding and removing infrastructure
1 parent 9b61e7d commit e4cbd2d

File tree

12 files changed

+869
-572
lines changed

12 files changed

+869
-572
lines changed

.github/workflows/common-test.yml

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ permissions:
2323
contents: write
2424

2525
env:
26-
DISABLE_PARALLEL_DEPLOY: false
2726
REAL_NPM: ${{ inputs.mode == 'global' || inputs.mode == 'local' }}
2827
TEST_MONOREPO: ${{ inputs.testMonorepo }}
2928
node_version: 22
@@ -74,14 +73,14 @@ jobs:
7473
run: npm run deploy
7574
working-directory: test/cdk-basic
7675
- name: Test
77-
run: npx vitest --retry 1 test/cdk-basic.test.ts
76+
run: npx vitest --retry 2 test/cdk-basic.test.ts
7877
- name: Test - observability mode
79-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/cdk-basic.test.ts
78+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/cdk-basic.test.ts
8079
- name: Deploy YAML version
8180
run: npm run deploy-yaml
8281
working-directory: test/cdk-basic
8382
- name: Test YAML
84-
run: npx vitest --retry 1 test/cdk-basic.test.ts
83+
run: npx vitest --retry 2 test/cdk-basic.test.ts
8584

8685
test-cdk-esm:
8786
runs-on: ubuntu-latest
@@ -128,9 +127,9 @@ jobs:
128127
run: npm run deploy
129128
working-directory: test/cdk-esm
130129
- name: Test
131-
run: npx vitest --retry 1 test/cdk-esm.test.ts
130+
run: npx vitest --retry 2 test/cdk-esm.test.ts
132131
- name: Test - observability mode
133-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/cdk-esm.test.ts
132+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/cdk-esm.test.ts
134133

135134
test-sls-basic:
136135
runs-on: ubuntu-latest
@@ -178,9 +177,9 @@ jobs:
178177
run: npm run deploy
179178
working-directory: test/sls-basic
180179
- name: Test
181-
run: npx vitest --retry 1 test/sls-basic.test.ts
180+
run: npx vitest --retry 2 test/sls-basic.test.ts
182181
- name: Test - observability mode
183-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-basic.test.ts
182+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/sls-basic.test.ts
184183

185184
test-sls-esbuild-cjs:
186185
runs-on: ubuntu-latest
@@ -228,9 +227,9 @@ jobs:
228227
run: npm run deploy
229228
working-directory: test/sls-esbuild-cjs
230229
- name: Test
231-
run: npx vitest --retry 1 test/sls-esbuild-cjs.test.ts
230+
run: npx vitest --retry 2 test/sls-esbuild-cjs.test.ts
232231
- name: Test - observability mode
233-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-cjs.test.ts
232+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/sls-esbuild-cjs.test.ts
234233

235234
test-sls-esbuild-esm:
236235
runs-on: ubuntu-latest
@@ -278,9 +277,9 @@ jobs:
278277
run: npm run deploy
279278
working-directory: test/sls-esbuild-esm
280279
- name: Test
281-
run: npx vitest --retry 1 test/sls-esbuild-esm.test.ts
280+
run: npx vitest --retry 2 test/sls-esbuild-esm.test.ts
282281
- name: Test - observability mode
283-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sls-esbuild-esm.test.ts
282+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/sls-esbuild-esm.test.ts
284283

285284
test-osls-basic:
286285
runs-on: ubuntu-latest
@@ -328,9 +327,9 @@ jobs:
328327
run: npm run deploy
329328
working-directory: test/osls-basic
330329
- name: Test
331-
run: npx vitest --retry 1 test/osls-basic.test.ts
330+
run: npx vitest --retry 2 test/osls-basic.test.ts
332331
- name: Test - observability mode
333-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/osls-basic.test.ts
332+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/osls-basic.test.ts
334333

335334
test-osls-esbuild-cjs:
336335
runs-on: ubuntu-latest
@@ -378,9 +377,9 @@ jobs:
378377
run: npm run deploy
379378
working-directory: test/osls-esbuild-cjs
380379
- name: Test
381-
run: npx vitest --retry 1 test/osls-esbuild-cjs.test.ts
380+
run: npx vitest --retry 2 test/osls-esbuild-cjs.test.ts
382381
- name: Test - observability mode
383-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/osls-esbuild-cjs.test.ts
382+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/osls-esbuild-cjs.test.ts
384383

385384
test-osls-esbuild-esm:
386385
runs-on: ubuntu-latest
@@ -428,9 +427,9 @@ jobs:
428427
run: npm run deploy
429428
working-directory: test/osls-esbuild-esm
430429
- name: Test
431-
run: npx vitest --retry 1 test/osls-esbuild-esm.test.ts
430+
run: npx vitest --retry 2 test/osls-esbuild-esm.test.ts
432431
- name: Test - observability mode
433-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/osls-esbuild-esm.test.ts
432+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/osls-esbuild-esm.test.ts
434433

435434
test-sam-basic:
436435
runs-on: ubuntu-latest
@@ -481,9 +480,9 @@ jobs:
481480
run: npm run deploy
482481
working-directory: test/sam-basic
483482
- name: Test
484-
run: npx vitest --retry 1 test/sam-basic.test.ts
483+
run: npx vitest --retry 2 test/sam-basic.test.ts
485484
- name: Test - observability mode
486-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sam-basic.test.ts
485+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/sam-basic.test.ts
487486

488487
test-sam-alt:
489488
runs-on: ubuntu-latest
@@ -534,9 +533,9 @@ jobs:
534533
run: npm run deploy
535534
working-directory: test/sam-alt
536535
- name: Test
537-
run: npx vitest --retry 1 test/sam-alt.test.ts
536+
run: npx vitest --retry 2 test/sam-alt.test.ts
538537
- name: Test - observability mode
539-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/sam-alt.test.ts
538+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/sam-alt.test.ts
540539

541540
test-terraform-basic:
542541
runs-on: ubuntu-latest
@@ -590,9 +589,9 @@ jobs:
590589
run: npm run deploy
591590
working-directory: test/terraform-basic
592591
- name: Test
593-
run: npx vitest --retry 1 test/terraform-basic.test.ts
592+
run: npx vitest --retry 2 test/terraform-basic.test.ts
594593
- name: Test - observability mode
595-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/terraform-basic.test.ts
594+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/terraform-basic.test.ts
596595

597596
test-opentofu-basic:
598597
runs-on: ubuntu-latest
@@ -646,6 +645,6 @@ jobs:
646645
run: npm run deploy
647646
working-directory: test/opentofu-basic
648647
- name: Test
649-
run: npx vitest --retry 1 test/opentofu-basic.test.ts
648+
run: npx vitest --retry 2 test/opentofu-basic.test.ts
650649
- name: Test - observability mode
651-
run: OBSERVABLE_MODE=true npx vitest --retry 1 test/opentofu-basic.test.ts
650+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/opentofu-basic.test.ts

.github/workflows/publish.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ run-name: >
66
77
on:
88
workflow_dispatch:
9-
inputs:
10-
release-type:
11-
description: 'Release type'
12-
required: true
13-
default: 'stable'
14-
type: choice
15-
options:
16-
- stable
17-
- alpha
18-
- beta
199

2010
permissions:
2111
id-token: write

.github/workflows/pull-request.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,41 @@ jobs:
1515
uses: ./.github/workflows/common-build.yml
1616
secrets: inherit
1717

18+
remove-old-layers:
19+
runs-on: ubuntu-latest
20+
needs: build
21+
concurrency:
22+
group: remove-all-layers
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Use Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: ${{ env.node_version }}
29+
registry-url: 'https://registry.npmjs.org'
30+
- name: Install dependencies
31+
run: npm ci
32+
- name: Download build artifact
33+
uses: actions/download-artifact@v4
34+
with:
35+
name: dist
36+
path: dist
37+
- name: Configure AWS Credentials
38+
uses: aws-actions/configure-aws-credentials@v4
39+
with:
40+
aws-region: eu-west-1
41+
role-to-assume: ${{ secrets.AWS_ROLE }}
42+
role-session-name: GitHubActions
43+
- name: Remove old layers
44+
run: |
45+
node ../../dist/lldebugger.mjs -r all --config-env=test -v
46+
# Picking random test so I can have environment
47+
working-directory: test/sam-basic
48+
1849
test:
1950
uses: ./.github/workflows/common-test.yml
2051
secrets: inherit
21-
needs: build
52+
needs: remove-old-layers
2253
with:
2354
mode: build
2455
testMonorepo: false

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Serverless is amazing and solves many issues with traditional systems. However,
2121

2222
Lambda Live Debugger connects to your deployed Lambda, routes requests to your computer, and sends responses back to the deployed Lambda. This allows you to debug locally, but the system behaves as if the code is running in the cloud with the same permissions. In case of code changes, you do not have to redeploy. The code is reloaded automatically without deploying or even restarting the debugger.
2323

24-
The tool attaches Lambda Extensions (via a Layer), intercepts, and relays calls to AWS IoT. AWS IoT transfers messages between your Lambda and the local machine. If the Lambda is written in TypeScript, it's transpiled to JavaScript. The code is executed via the Node Worker Thread.
24+
The tool attaches Lambda Extensions (via a layer), intercepts, and relays calls to AWS IoT. AWS IoT transfers messages between your Lambda and the local machine. If the Lambda is written in TypeScript, it's transpiled to JavaScript. The code is executed via the Node Worker Thread.
2525

2626
![Architecture](./public/architecture.drawio.png)
2727

@@ -34,11 +34,11 @@ AWS keys generated on the cloud for Lambda are transferred to the local environm
3434

3535
Lambda Live Debugger makes the following changes to your AWS infrastructure:
3636

37-
- Deploys the Lambda Layer
38-
- Attaches the Layer to each Lambda you're debugging
37+
- Deploys the Lambda layer
38+
- Attaches the layer to each Lambda you're debugging
3939
- Adds a policy to the Lambda Role for AWS IoT access
4040

41-
In case you do not want to debug all functions and add the Layer to them, you can limit to the ones you need via the `function` parameter.
41+
In case you do not want to debug all functions and add the layer to them, you can limit to the ones you need via the `function` parameter.
4242

4343
The tool generates temporary files in the `.lldebugger` folder, which can be deleted after debugging. The wizard can add `.lldebugger` to `.gitignore` for you.
4444

@@ -109,7 +109,7 @@ The configuration is saved to `lldebugger.config.ts`.
109109

110110
```
111111
-V, --version output the version number
112-
-r, --remove [option] Remove Lambda Live Debugger infrastructure. Options: 'keep-layer' (default), 'all'. The latest also removes the Lambda Layer
112+
-r, --remove [option] Remove Lambda Live Debugger infrastructure. Options: 'keep-layer' (default), 'all'. The latest also removes the Lambda layer
113113
-w, --wizard Program interactively asks for each parameter and saves it to lldebugger.config.ts
114114
-v, --verbose Verbose logging
115115
-c, --context <context> AWS CDK context (default: [])
@@ -187,9 +187,9 @@ When you no longer want to debug and want Lambda to execute the code deployed to
187187
lld -r
188188
```
189189

190-
This detaches the Layer from your Lambdas and removes the IoT permission policy. It will not remove the Layer because others might use it.
190+
This detaches the layer from your Lambdas and removes the IoT permission policy. It will not remove the layer because others might use it.
191191

192-
To also remove the Layer:
192+
To also remove the layer:
193193

194194
```
195195
lld -r=all

src/configuration.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { LambdaProps } from './types/lambdaProps.js';
21
import { LldConfig } from './types/lldConfig.js';
32
import { LambdaResource } from './types/resourcesDiscovery.js';
43
import * as crypto from 'crypto';
@@ -12,7 +11,7 @@ import { ResourceDiscovery } from './resourceDiscovery.js';
1211
import { Logger } from './logger.js';
1312

1413
let config: LldConfig;
15-
const lambdas: Record<string, LambdaProps> = {};
14+
const lambdas: Record<string, LambdaResource> = {};
1615
let lambdasList: LambdaResource[] | undefined = undefined;
1716

1817
/**
@@ -103,34 +102,43 @@ async function generateDebuggerId(observableMode: boolean) {
103102
* Add a Lambda to the configuration
104103
* @param props
105104
*/
106-
function addLambda(props: Omit<LambdaProps, 'functionId'>) {
105+
function addLambda(props: LambdaResource) {
107106
lambdas[props.functionName] = {
108-
functionId: props.functionName,
109107
...props,
110108
};
111109
}
112110

113111
/**
114-
* Get a Lambda by functionId
115-
* @param functionId
112+
* Get a Lambda by name
113+
* @param functionName
116114
* @returns
117115
*/
118-
async function getLambda(functionId: string): Promise<LambdaProps> {
119-
const lambda = lambdas[functionId];
116+
async function getLambda(functionName: string): Promise<LambdaResource> {
117+
const lambda = lambdas[functionName];
120118

121119
if (lambda) return lambda;
122120

123-
throw new Error(`Lambda not found: ${functionId}`);
121+
throw new Error(`Lambda not found: ${functionName}`);
124122
}
125123

126124
/**
127125
* Get all Lambdas
128126
* @returns
129127
*/
130-
function getLambdas() {
128+
function getLambdasAll(): LambdaResource[] {
131129
return Object.values(lambdas);
132130
}
133131

132+
/**
133+
* Get filtered Lambdas
134+
* @returns
135+
*/
136+
function getLambdasFiltered() {
137+
const list = Object.values(lambdas);
138+
139+
return list.filter((l) => !l.filteredOut);
140+
}
141+
134142
/**
135143
* Discover Lambdas
136144
*/
@@ -180,7 +188,7 @@ function saveDiscoveredLambdas(lambdasListNew: LambdaResource[]) {
180188

181189
Logger.log('Found the following Lambdas to debug:');
182190
Logger.log(
183-
` - ${getLambdas()
191+
` - ${getLambdasFiltered()
184192
.map((f) => `${f.functionName} code: ${f.codePath}`)
185193
.join('\n - ')}`,
186194
);
@@ -205,6 +213,7 @@ export const Configuration = {
205213
},
206214
discoverLambdas,
207215
getLambda,
208-
getLambdas,
216+
getLambdasAll,
217+
getLambdasFiltered,
209218
setConfig,
210219
};

src/configuration/getConfigFromCliArgs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function getConfigFromCliArgs(
2020
program.name('lld').description('Lambda Live Debugger').version(version);
2121
program.option(
2222
'-r, --remove [option]',
23-
"Remove Lambda Live Debugger infrastructure. Options: 'keep-layer' (default), 'all'. The latest also removes the Lambda Layer",
23+
"Remove Lambda Live Debugger infrastructure. Options: 'keep-layer' (default), 'all'. The latest also removes the Lambda layer",
2424
//validateRemoveOption,
2525
//"keep-layer"
2626
);

0 commit comments

Comments
 (0)