Skip to content

Commit a29bd03

Browse files
authored
fix(samcli): support legacy templates.json parameter overrides (#3005)
1 parent b53a07a commit a29bd03

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/shared/sam/sync.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { asEnvironmentVariables } from '../../credentials/credentialsUtilities'
3838
import { SamCliInfoInvocation } from './cli/samCliInfo'
3939
import { parse } from 'semver'
4040
import { isAutomation } from '../vscode/env'
41+
import { getOverriddenParameters } from '../../lambda/config/parameterUtils'
4142

4243
export interface SyncParams {
4344
readonly region: string
@@ -320,11 +321,32 @@ async function runSyncInTerminal(proc: ChildProcess) {
320321
}
321322
}
322323

324+
async function loadLegacyParameterOverrides(template: TemplateItem) {
325+
try {
326+
const params = await getOverriddenParameters(template.uri)
327+
if (!params) {
328+
return
329+
}
330+
331+
return [...params.entries()].map(([k, v]) => `${k}=${v}`)
332+
} catch (err) {
333+
getLogger().warn(`sam: unable to load legacy parameter overrides: %s`, err)
334+
}
335+
}
336+
323337
export async function runSamSync(args: SyncParams) {
324338
telemetry.record({ lambdaPackageType: args.ecrRepoUri !== undefined ? 'Image' : 'Zip' })
325339

326340
const samCliPath = await getSamCliPath()
327341
const { boundArgs } = await saveAndBindArgs(args)
342+
const overrides = await loadLegacyParameterOverrides(args.template)
343+
if (overrides !== undefined) {
344+
// Leaving this out of the definitions file as this is _very_ niche and specific to the
345+
// implementation. Plus we would have to redefine `sam_sync` to add it.
346+
telemetry.record({ isUsingTemplatesJson: true } as any)
347+
boundArgs.push('--parameter-overrides', ...overrides)
348+
}
349+
328350
const sam = new ChildProcess(samCliPath, ['sync', ...boundArgs], {
329351
spawnOptions: {
330352
cwd: args.projectRoot.fsPath,

0 commit comments

Comments
 (0)