Skip to content

Commit c4c94da

Browse files
feat: SAM nested stack (#152)
1 parent 2e6b640 commit c4c94da

File tree

23 files changed

+1023
-33
lines changed

23 files changed

+1023
-33
lines changed

.github/workflows/common-test.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,55 @@ jobs:
131131
- name: Test - observability mode
132132
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/cdk-esm.test.ts
133133

134+
test-cdk-nested:
135+
runs-on: ubuntu-latest
136+
concurrency:
137+
group: test-cdk-nested
138+
steps:
139+
- uses: actions/checkout@v4
140+
- name: Use Node.js
141+
uses: actions/setup-node@v4
142+
with:
143+
node-version: ${{ env.node_version }}
144+
registry-url: 'https://registry.npmjs.org'
145+
- name: Install dependencies
146+
run: |
147+
node prepareForTest.js cdk-nested
148+
npm i
149+
- name: Download build artifact
150+
uses: actions/download-artifact@v4
151+
if: ${{ inputs.mode == 'build' }}
152+
with:
153+
name: dist
154+
path: dist
155+
- name: Install lambda-live-debugger globally
156+
if: ${{ inputs.mode == 'global' }}
157+
run: |
158+
npm i lambda-live-debugger@${{ inputs.version || 'latest' }} -g
159+
working-directory: test
160+
- name: Install lambda-live-debugger locally
161+
if: ${{ inputs.mode == 'local' }}
162+
run: |
163+
npm i lambda-live-debugger@${{ inputs.version || 'latest' }}
164+
working-directory: test
165+
- name: Configure AWS Credentials
166+
uses: aws-actions/configure-aws-credentials@v4
167+
with:
168+
aws-region: eu-west-1
169+
role-to-assume: ${{ secrets.AWS_ROLE }}
170+
role-session-name: GitHubActions
171+
- name: Destroy
172+
run: npm run destroy
173+
working-directory: test/cdk-nested
174+
continue-on-error: true
175+
- name: Deploy
176+
run: npm run deploy
177+
working-directory: test/cdk-nested
178+
- name: Test
179+
run: npx vitest --retry 2 test/cdk-nested.test.ts
180+
- name: Test - observability mode
181+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/cdk-nested.test.ts
182+
134183
test-sls-basic:
135184
runs-on: ubuntu-latest
136185
concurrency:
@@ -484,6 +533,59 @@ jobs:
484533
- name: Test - observability mode
485534
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/sam-basic.test.ts
486535

536+
test-sam-nested:
537+
runs-on: ubuntu-latest
538+
concurrency:
539+
group: test-sam-nested
540+
steps:
541+
- uses: actions/checkout@v4
542+
- uses: aws-actions/setup-sam@v2
543+
with:
544+
use-installer: true
545+
token: ${{ secrets.GITHUB_TOKEN }}
546+
- name: Use Node.js
547+
uses: actions/setup-node@v4
548+
with:
549+
node-version: ${{ env.node_version }}
550+
registry-url: 'https://registry.npmjs.org'
551+
- name: Install dependencies
552+
run: |
553+
node prepareForTest.js sam-nested
554+
npm i
555+
- name: Download build artifact
556+
uses: actions/download-artifact@v4
557+
if: ${{ inputs.mode == 'build' }}
558+
with:
559+
name: dist
560+
path: dist
561+
- name: Install lambda-live-debugger globally
562+
if: ${{ inputs.mode == 'global' }}
563+
run: |
564+
npm i lambda-live-debugger@${{ inputs.version || 'latest' }} -g
565+
working-directory: test
566+
- name: Install lambda-live-debugger locally
567+
if: ${{ inputs.mode == 'local' }}
568+
run: |
569+
npm i lambda-live-debugger@${{ inputs.version || 'latest' }}
570+
working-directory: test
571+
- name: Configure AWS Credentials
572+
uses: aws-actions/configure-aws-credentials@v4
573+
with:
574+
aws-region: eu-west-1
575+
role-to-assume: ${{ secrets.AWS_ROLE }}
576+
role-session-name: GitHubActions
577+
- name: Destroy
578+
run: npm run destroy
579+
working-directory: test/sam-nested
580+
continue-on-error: true
581+
- name: Deploy
582+
run: npm run deploy
583+
working-directory: test/sam-nested
584+
- name: Test
585+
run: npx vitest --retry 2 test/sam-nested.test.ts
586+
- name: Test - observability mode
587+
run: OBSERVABLE_MODE=true npx vitest --retry 2 test/sam-nested.test.ts
588+
487589
test-sam-alt:
488590
runs-on: ubuntu-latest
489591
concurrency:

.vscode/launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,26 @@
230230
"type": "node",
231231
"cwd": "${workspaceRoot}/test/sam-basic"
232232
},
233+
{
234+
"name": "LLDebugger - SAM nested",
235+
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
236+
"args": ["../../src/lldebugger.ts", "--config-env=test"],
237+
"request": "launch",
238+
"skipFiles": ["<node_internals>/**"],
239+
"console": "integratedTerminal",
240+
"type": "node",
241+
"cwd": "${workspaceRoot}/test/sam-nested"
242+
},
243+
{
244+
"name": "LLDebugger - SAM nested - observability",
245+
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
246+
"args": ["../../src/lldebugger.ts", "--config-env=test", "-o"],
247+
"request": "launch",
248+
"skipFiles": ["<node_internals>/**"],
249+
"console": "integratedTerminal",
250+
"type": "node",
251+
"cwd": "${workspaceRoot}/test/sam-nested"
252+
},
233253
{
234254
"name": "LLDebugger - SAM alt",
235255
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
"test-osls-esbuild-esm-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/osls-esbuild-esm.test.ts",
7171
"test-sam-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/sam-basic.test.ts",
7272
"test-sam-basic-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sam-basic.test.ts",
73+
"test-sam-nested": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/sam-nested.test.ts",
74+
"test-sam-nested-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sam-nested.test.ts",
7375
"test-sam-alt": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/sam-alt.test.ts",
7476
"test-sam-alt-observable": "npm run build && RUN_TEST_FROM_CLI=true OBSERVABLE_MODE=true vitest run test/sam-alt.test.ts",
7577
"test-terraform-basic": "npm run build && RUN_TEST_FROM_CLI=true vitest run test/terraform-basic.test.ts",
@@ -161,6 +163,7 @@
161163
"test/osls-esbuild",
162164
"test/osls-esbuild-cjs",
163165
"test/sam-basic",
166+
"test/sam-nested",
164167
"test/sam-alt",
165168
"test/terraform-basic",
166169
"test/opentofu-basic"

src/cloudFormation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ async function getCloudFormationResources(
139139
async function getLambdasInStack(
140140
stackName: string,
141141
awsConfiguration: AwsConfiguration,
142+
stackLogicalId?: string,
142143
): Promise<
143144
Array<{
144145
lambdaName: string;
145146
logicalId: string;
146147
stackName: string;
148+
stackLogicalId: string;
147149
}>
148150
> {
149151
const response = await getCloudFormationResources(
@@ -165,6 +167,7 @@ async function getLambdasInStack(
165167
lambdaName: resource.PhysicalResourceId!,
166168
logicalId: resource.LogicalResourceId!,
167169
stackName: stackName,
170+
stackLogicalId: stackLogicalId ?? stackName,
168171
};
169172
}) ?? [];
170173

@@ -175,6 +178,7 @@ async function getLambdasInStack(
175178
const lambdasInNestedStack = await getLambdasInStack(
176179
nestedStack.PhysicalResourceId,
177180
awsConfiguration,
181+
nestedStack.LogicalResourceId,
178182
);
179183

180184
return lambdasInNestedStack;

0 commit comments

Comments
 (0)