Skip to content

Commit 0ca95aa

Browse files
fix: SAM nested stack
1 parent caa1ffa commit 0ca95aa

File tree

7 files changed

+279
-2
lines changed

7 files changed

+279
-2
lines changed

test/sam-basic.test.ts

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { getTestProjectFolder } from './utils/getTestProjectFolder.js';
1414

1515
export const execAsync = promisify(exec);
1616

17-
const observableMode = process.env.OBSERVABLE_MODE === 'true';
17+
export const observableMode = process.env.OBSERVABLE_MODE === 'true';
1818

1919
describe('sam-basic', async () => {
2020
const folder = await getTestProjectFolder('sam-basic');
@@ -103,6 +103,102 @@ describe('sam-basic', async () => {
103103
}
104104
});
105105

106+
test('call Lambda - testTsCommonJsFromNestedStack', async () => {
107+
const lambdaName = await getSamFunctionName(
108+
folder,
109+
'FunctionNameTestTsCommonJsFromNestedStack',
110+
);
111+
112+
const payload = getSamplePayload(lambdaName);
113+
const response = await callLambda(lambdaName, payload);
114+
115+
expect(response.inputEvent).toEqual(payload);
116+
expect(response.runningLocally).toEqual(!observableMode);
117+
if (observableMode) {
118+
await validateLocalResponse(lambdaName, payload);
119+
}
120+
});
121+
122+
test('call Lambda - testTsEsModuleFromNestedStack', async () => {
123+
const lambdaName = await getSamFunctionName(
124+
folder,
125+
'FunctionNameTestTsEsModuleFromNestedStack',
126+
);
127+
128+
const payload = getSamplePayload(lambdaName);
129+
const response = await callLambda(lambdaName, payload);
130+
131+
expect(response.inputEvent).toEqual(payload);
132+
expect(response.runningLocally).toEqual(!observableMode);
133+
if (observableMode) {
134+
await validateLocalResponse(lambdaName, payload);
135+
}
136+
});
137+
138+
test('call Lambda - testJsCommonJsFromNestedStack', async () => {
139+
const lambdaName = await getSamFunctionName(
140+
folder,
141+
'FunctionNameTestJsCommonJsFromNestedStack',
142+
);
143+
144+
const payload = getSamplePayload(lambdaName);
145+
const response = await callLambda(lambdaName, payload);
146+
147+
expect(response.runningLocally).toEqual(!observableMode);
148+
expect(response.inputEvent).toEqual(payload);
149+
if (observableMode) {
150+
await validateLocalResponse(lambdaName, payload);
151+
}
152+
});
153+
154+
test('call Lambda - testTsCommonJsNested', async () => {
155+
const lambdaName = await getSamFunctionName(
156+
folder,
157+
'FunctionNameTestTsCommonJsNested',
158+
);
159+
160+
const payload = getSamplePayload(lambdaName);
161+
const response = await callLambda(lambdaName, payload);
162+
163+
expect(response.inputEvent).toEqual(payload);
164+
expect(response.runningLocally).toEqual(!observableMode);
165+
if (observableMode) {
166+
await validateLocalResponse(lambdaName, payload);
167+
}
168+
});
169+
170+
test('call Lambda - testTsEsModuleNested', async () => {
171+
const lambdaName = await getSamFunctionName(
172+
folder,
173+
'FunctionNameTestTsEsModuleNested',
174+
);
175+
176+
const payload = getSamplePayload(lambdaName);
177+
const response = await callLambda(lambdaName, payload);
178+
179+
expect(response.inputEvent).toEqual(payload);
180+
expect(response.runningLocally).toEqual(!observableMode);
181+
if (observableMode) {
182+
await validateLocalResponse(lambdaName, payload);
183+
}
184+
});
185+
186+
test('call Lambda - testJsCommonJsNested', async () => {
187+
const lambdaName = await getSamFunctionName(
188+
folder,
189+
'FunctionNameTestJsCommonJsNested',
190+
);
191+
192+
const payload = getSamplePayload(lambdaName);
193+
const response = await callLambda(lambdaName, payload);
194+
195+
expect(response.runningLocally).toEqual(!observableMode);
196+
expect(response.inputEvent).toEqual(payload);
197+
if (observableMode) {
198+
await validateLocalResponse(lambdaName, payload);
199+
}
200+
});
201+
106202
test('remove infra', async () => {
107203
if (process.env.CI === 'true' || process.env.RUN_TEST_FROM_CLI === 'true') {
108204
await removeInfra(lldProcess, folder, ['--config-env=test']);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Description: >-
3+
Nested Nested Stack for sam-basic
4+
5+
Transform:
6+
- AWS::Serverless-2016-10-31
7+
8+
Resources:
9+
testTsCommonJs:
10+
Type: AWS::Serverless::Function
11+
Properties:
12+
CodeUri: services/testTsCommonJs/
13+
Handler: lambda.lambdaHandler
14+
Runtime: nodejs22.x
15+
Architectures:
16+
- x86_64
17+
MemorySize: 128
18+
Timeout: 10
19+
Policies:
20+
- AWSLambdaBasicExecutionRole
21+
Metadata:
22+
BuildMethod: esbuild
23+
BuildProperties:
24+
Format: cjs
25+
Minify: true
26+
Target: 'es2020'
27+
Sourcemap: true
28+
EntryPoints:
29+
- lambda.ts
30+
31+
testTsEsModule:
32+
Type: AWS::Serverless::Function
33+
Properties:
34+
CodeUri: services/testTsEsModule/
35+
Handler: lambda.lambdaHandler
36+
Runtime: nodejs22.x
37+
Architectures:
38+
- x86_64
39+
MemorySize: 128
40+
Timeout: 10
41+
Policies:
42+
- AWSLambdaBasicExecutionRole
43+
Metadata:
44+
BuildMethod: esbuild
45+
BuildProperties:
46+
Format: esm
47+
OutExtension:
48+
- .js=.mjs
49+
Minify: true
50+
Target: 'es2020'
51+
Sourcemap: true
52+
Banner:
53+
- js=import { createRequire } from 'module'; const require = createRequire(import.meta.url);
54+
EntryPoints:
55+
- lambda.ts
56+
57+
testJsCommonJs:
58+
Type: AWS::Serverless::Function
59+
Properties:
60+
Handler: services/testJsCommonJs/lambda.lambdaHandler
61+
Runtime: nodejs22.x
62+
Architectures:
63+
- x86_64
64+
MemorySize: 128
65+
Timeout: 10
66+
Policies:
67+
- AWSLambdaBasicExecutionRole
68+
69+
Outputs:
70+
FunctionNameTestTsCommonJsNested:
71+
Value: !Ref testTsCommonJs
72+
FunctionNameTestTsEsModuleNested:
73+
Value: !Ref testTsEsModule
74+
FunctionNameTestJsCommonJsNested:
75+
Value: !Ref testJsCommonJs

test/sam-basic/nested-stack.yaml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Description: >-
3+
Nested Stack for sam-basic
4+
5+
Transform:
6+
- AWS::Serverless-2016-10-31
7+
8+
Resources:
9+
NestedNestedStack:
10+
Type: AWS::Serverless::Application
11+
Properties:
12+
Location: nested-nested-stack.yaml
13+
14+
testTsCommonJs:
15+
Type: AWS::Serverless::Function
16+
Properties:
17+
CodeUri: services/testTsCommonJs/
18+
Handler: lambda.lambdaHandler
19+
Runtime: nodejs22.x
20+
Architectures:
21+
- x86_64
22+
MemorySize: 128
23+
Timeout: 10
24+
Policies:
25+
- AWSLambdaBasicExecutionRole
26+
Metadata:
27+
BuildMethod: esbuild
28+
BuildProperties:
29+
Format: cjs
30+
Minify: true
31+
Target: 'es2020'
32+
Sourcemap: true
33+
EntryPoints:
34+
- lambda.ts
35+
36+
testTsEsModule:
37+
Type: AWS::Serverless::Function
38+
Properties:
39+
CodeUri: services/testTsEsModule/
40+
Handler: lambda.lambdaHandler
41+
Runtime: nodejs22.x
42+
Architectures:
43+
- x86_64
44+
MemorySize: 128
45+
Timeout: 10
46+
Policies:
47+
- AWSLambdaBasicExecutionRole
48+
Metadata:
49+
BuildMethod: esbuild
50+
BuildProperties:
51+
Format: esm
52+
OutExtension:
53+
- .js=.mjs
54+
Minify: true
55+
Target: 'es2020'
56+
Sourcemap: true
57+
Banner:
58+
- js=import { createRequire } from 'module'; const require = createRequire(import.meta.url);
59+
EntryPoints:
60+
- lambda.ts
61+
62+
testJsCommonJs:
63+
Type: AWS::Serverless::Function
64+
Properties:
65+
Handler: services/testJsCommonJs/lambda.lambdaHandler
66+
Runtime: nodejs22.x
67+
Architectures:
68+
- x86_64
69+
MemorySize: 128
70+
Timeout: 10
71+
Policies:
72+
- AWSLambdaBasicExecutionRole
73+
74+
Outputs:
75+
FunctionNameTestTsCommonJs:
76+
Value: !Ref testTsCommonJs
77+
FunctionNameTestTsEsModule:
78+
Value: !Ref testTsEsModule
79+
FunctionNameTestJsCommonJs:
80+
Value: !Ref testJsCommonJs
81+
# Pass through outputs from nested-nested stack
82+
FunctionNameTestTsCommonJsNested:
83+
Value: !GetAtt NestedNestedStack.Outputs.FunctionNameTestTsCommonJsNested
84+
FunctionNameTestTsEsModuleNested:
85+
Value: !GetAtt NestedNestedStack.Outputs.FunctionNameTestTsEsModuleNested
86+
FunctionNameTestJsCommonJsNested:
87+
Value: !GetAtt NestedNestedStack.Outputs.FunctionNameTestJsCommonJsNested

test/sam-basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "sam build",
7-
"deploy": "npm run build && sam deploy --config-env test --no-confirm-changeset && npm run export_outputs",
7+
"deploy": "npm run build && sam deploy --config-env test --no-confirm-changeset --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND && npm run export_outputs",
88
"export_outputs": "aws cloudformation describe-stacks --stack-name lld-test-sam-basic --output json --query Stacks[0].Outputs > sam-outputs.json",
99
"destroy": "sam delete --config-env test --no-prompts"
1010
},

test/sam-basic/template.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Transform:
66
- AWS::Serverless-2016-10-31
77

88
Resources:
9+
NestedStack:
10+
Type: AWS::Serverless::Application
11+
Properties:
12+
Location: nested-stack.yaml
13+
914
testTsCommonJs:
1015
Type: AWS::Serverless::Function
1116
Properties:
@@ -87,3 +92,17 @@ Outputs:
8792
Value: !Ref testTsCommonJs
8893
FunctionNameTestTsEsModule:
8994
Value: !Ref testTsEsModule
95+
# Outputs from nested stack
96+
FunctionNameTestTsCommonJsFromNestedStack:
97+
Value: !GetAtt NestedStack.Outputs.FunctionNameTestTsCommonJs
98+
FunctionNameTestTsEsModuleFromNestedStack:
99+
Value: !GetAtt NestedStack.Outputs.FunctionNameTestTsEsModule
100+
FunctionNameTestJsCommonJsFromNestedStack:
101+
Value: !GetAtt NestedStack.Outputs.FunctionNameTestJsCommonJs
102+
# Outputs from nested-nested stack (via nested stack)
103+
FunctionNameTestTsCommonJsNested:
104+
Value: !GetAtt NestedStack.Outputs.FunctionNameTestTsCommonJsNested
105+
FunctionNameTestTsEsModuleNested:
106+
Value: !GetAtt NestedStack.Outputs.FunctionNameTestTsEsModuleNested
107+
FunctionNameTestJsCommonJsNested:
108+
Value: !GetAtt NestedStack.Outputs.FunctionNameTestJsCommonJsNested

test/sls-basic/nested-nested-stack.yml

Whitespace-only changes.

test/sls-basic/nested-stack.yml

Whitespace-only changes.

0 commit comments

Comments
 (0)