Skip to content

Commit 96126ab

Browse files
committed
samCliLocalInvoke.ts: fix environment spec
Problem: ENOENT error during the "sam invoke" step when attempting to debug, which causes SAM debug to fail: Building SAM Application... Build complete. Starting the SAM Application locally (see Terminal for output) Running command: sam local invoke awsToolkitSamLocalResource --template … --event … --env-vars … -d 5883 Error running local SAM Application: spawn sam ENOENT Waiting for SAM Application to start before attaching debugger... Local invoke of SAM Application has ended. Solution: When setting env vars one must also copy the current environment, else it is discarded. NB: the localLambdaRunner.ts change is not directly related.
1 parent 2ba6b2e commit 96126ab

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/shared/sam/cli/samCliLocalInvoke.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ export class SamCliLocalInvokeInvocation {
217217

218218
await this.args.invoker.invoke({
219219
options: {
220-
env: this.args.environmentVariables,
220+
env: {
221+
...process.env,
222+
...this.args.environmentVariables,
223+
},
221224
},
222225
command: 'sam',
223226
args: invokeArgs,

src/shared/sam/localLambdaRunner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export async function invokeLambdaFunction(
154154
if (!config.noDebug) {
155155
// Needed at least for dotnet case; harmless for others.
156156
samCliArgs.environmentVariables = {
157+
...samCliArgs.environmentVariables,
157158
SAM_BUILD_MODE: 'debug',
158159
}
159160
}

src/shared/utilities/childProcess.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ export class ChildProcess {
7373
}
7474

7575
getLogger().info(`Running command: ${this.process} ${this.args.join(' ')}`)
76+
77+
// Async.
78+
// See also crossSpawn.spawnSync().
79+
// Arguments are forwarded[1] to node `child_process` module, see its documentation[2].
80+
// [1] https://github.com/moxystudio/node-cross-spawn/blob/master/index.js
81+
// [2] https://nodejs.org/api/child_process.html
7682
this.childProcess = crossSpawn(this.process, this.args, this.options)
7783

7884
this.childProcess.stdout?.on('data', (data: { toString(): string }) => {

0 commit comments

Comments
 (0)