Skip to content

Commit 57fa1d6

Browse files
authored
feat(lambda): SAM local invoke can accept a runtime parameter aws#6724
## Problem Customers are not able to local invoke with the runtime selected in the webview UI. Currently the runtime used is the one specified on the template. The feature was already added to SAMCLI aws/aws-sam-cli#7885. ## Solution Allows customers to change runtimes when locally invoking in the local invoke webview, without having to change it in their template and rebuilding. Under the hood, the newly added ```--runtime``` option will be appended to the ```samcli``` command.
1 parent 99a555a commit 57fa1d6

File tree

4 files changed

+116
-177
lines changed

4 files changed

+116
-177
lines changed

packages/core/src/shared/sam/cli/samCliLocalInvoke.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import globals from '../../extensionGlobals'
1515
import { SamCliSettings } from './samCliSettings'
1616
import { addTelemetryEnvVar, collectSamErrors, SamCliError } from './samCliInvokerUtils'
1717
import { fs } from '../../fs/fs'
18+
import { Runtime } from 'aws-sdk/clients/lambda'
19+
import { getSamCliPathAndVersion } from '../utils'
20+
import { deprecatedRuntimes } from '../../../lambda/models/samLambdaRuntime'
1821

1922
const localize = nls.loadMessageBundle()
2023

@@ -217,6 +220,8 @@ export interface SamCliLocalInvokeInvocationArguments {
217220
name?: string
218221
/** AWS region */
219222
region?: string
223+
/** Overrides the template-specified runtime. */
224+
runtime?: Runtime
220225
}
221226

222227
/**
@@ -266,6 +271,17 @@ export class SamCliLocalInvokeInvocation {
266271
)
267272
invokeArgs.push(...(this.args.extraArgs ?? []))
268273

274+
// Get samcli version
275+
const { parsedVersion } = await getSamCliPathAndVersion()
276+
277+
// '--runtime' option for sam local invoke is only available in SAM CLI 1.135.0 and later
278+
if ((parsedVersion?.compare('1.135.0') ?? -1) >= 0) {
279+
// check if the runtime is valid (not deprecated)
280+
if (this.args.runtime && !deprecatedRuntimes.has(this.args.runtime)) {
281+
pushIf(invokeArgs, true, '--runtime', this.args.runtime)
282+
}
283+
}
284+
269285
return await this.args.invoker.invoke({
270286
options: {
271287
env: {

packages/core/src/shared/sam/localLambdaRunner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ async function invokeLambdaHandler(
247247
parameterOverrides: config.parameterOverrides,
248248
name: config.name,
249249
region: config.region,
250+
runtime: config.lambda?.runtime,
250251
}
251252

252253
// sam local invoke ...

0 commit comments

Comments
 (0)