Skip to content

Commit bc0c45b

Browse files
committed
SAM debugconfig: rename some fields
rename fields: samTemplatePath, samTemplateResource
1 parent d405e4e commit bc0c45b

19 files changed

+137
-151
lines changed

designs/sam-debugging/local-sam-debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ The required fields are: type, request, invokeTarget
179179
// Reference to the thing (Template or Code) being invoked
180180
"invokeTarget": {
181181
"target": "template", // template | code, influences fields expected by toolkit
182-
"samTemplatePath": "path to template yaml file",
182+
"templatePath": "path to template yaml file",
183183
"samTemplateResource": "HelloWorldResource" // Name of Template resource to debug
184184
},
185185
// Lambda Execution related arguments

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@
171171
"title": "Template Target Properties",
172172
"description": "%AWS.configuration.description.awssam.debug.invokeTarget%",
173173
"properties": {
174-
"samTemplatePath": {
175-
"description": "%AWS.configuration.description.awssam.debug.samTemplatePath%",
174+
"templatePath": {
175+
"description": "%AWS.configuration.description.awssam.debug.templatePath%",
176176
"type": "string"
177177
},
178-
"samTemplateResource": {
179-
"description": "%AWS.configuration.description.awssam.debug.samTemplateResource%",
178+
"logicalId": {
179+
"description": "%AWS.configuration.description.awssam.debug.logicalId%",
180180
"type": "string"
181181
},
182182
"target": {
@@ -189,8 +189,8 @@
189189
},
190190
"additionalProperties": false,
191191
"required": [
192-
"samTemplatePath",
193-
"samTemplateResource",
192+
"templatePath",
193+
"logicalId",
194194
"target"
195195
],
196196
"type": "object"
@@ -362,8 +362,8 @@
362362
"name": "${3:Invoke Lambda}",
363363
"invokeTarget": {
364364
"target": "template",
365-
"samTemplatePath": "${1:Template Location}",
366-
"samTemplateResource": "${2:Function Logical ID}"
365+
"templatePath": "${1:Template Location}",
366+
"logicalId": "${2:Function Logical ID}"
367367
},
368368
"lambda": {
369369
"event": {

package.nls.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757
"AWS.stepFunctions.graph.status.syncing": "Rendering ASL graph...",
5858
"AWS.configuration.description.awssam.debug.label": "AWS SAM: Debug Lambda Function Locally",
5959
"AWS.configuration.description.awssam.debug.invokeTarget": "Configures the application to launch",
60-
"AWS.configuration.description.awssam.debug.target": "The type of invocation to launch. Possible values:\n* `template` uses a SAM Template as an entrypoint\n* `code` invokes Lambda code directly.",
60+
"AWS.configuration.description.awssam.debug.target": "The type of invocation to launch. Possible values:\n* `template` uses a CFN/SAM Template as an entrypoint\n* `code` invokes Lambda code directly.",
6161
"AWS.configuration.description.awssam.debug.lambdaHandler": "Lambda Function handler to invoke.",
6262
"AWS.configuration.description.awssam.debug.projectRoot": "The root of the project, used to determine where in the file-system to locate the lambdaHandler.",
63-
"AWS.configuration.description.awssam.debug.samTemplatePath": "The path to the SAM Template.",
64-
"AWS.configuration.description.awssam.debug.samTemplateResource": "The LogicalID of the AWS::Lambda::Function or AWS::Serverless::Function to invoke.",
63+
"AWS.configuration.description.awssam.debug.templatePath": "Path to the CFN/SAM template.",
64+
"AWS.configuration.description.awssam.debug.logicalId": "Resource name of an AWS::Lambda::Function or AWS::Serverless::Function to invoke.",
6565
"AWS.configuration.description.awssam.debug.envvars": "Environment variables to pass to the function invocation (replaces template variables).",
6666
"AWS.configuration.description.awssam.debug.lambda": "Lambda specific details of the invocation",
6767
"AWS.configuration.description.awssam.debug.memoryMb": "The amount of memory (in Mb) the Lambda function has access to.",

src/integrationTest/sam.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('SAM Integration Tests', async () => {
215215
let subSuiteTestLocation: string
216216

217217
let samAppCodeUri: vscode.Uri
218-
let samTemplatePath: string
218+
let cfnTemplatePath: string
219219

220220
before(async function() {
221221
// tslint:disable-next-line: no-invalid-this
@@ -226,7 +226,7 @@ describe('SAM Integration Tests', async () => {
226226

227227
await createSamApplication(subSuiteTestLocation)
228228
const appPath = path.join(subSuiteTestLocation, samApplicationName, scenario.path)
229-
samTemplatePath = path.join(subSuiteTestLocation, samApplicationName, 'template.yaml')
229+
cfnTemplatePath = path.join(subSuiteTestLocation, samApplicationName, 'template.yaml')
230230
samAppCodeUri = await openSamAppFile(appPath)
231231
})
232232

@@ -245,7 +245,7 @@ describe('SAM Integration Tests', async () => {
245245
})
246246

247247
it('the SAM Template contains the expected runtime', async () => {
248-
const fileContents = readFileSync(samTemplatePath).toString()
248+
const fileContents = readFileSync(cfnTemplatePath).toString()
249249
assert.ok(fileContents.includes(`Runtime: ${scenario.runtime}`))
250250
})
251251

src/lambda/commands/createNewSamApp.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,15 @@ async function validateSamCli(samCliValidator: SamCliValidator): Promise<void> {
224224
async function getMainUri(
225225
config: Pick<CreateNewSamAppWizardResponse, 'location' | 'name'>
226226
): Promise<vscode.Uri | undefined> {
227-
const samTemplatePath = path.resolve(config.location.fsPath, config.name, 'template.yaml')
228-
if (await fileExists(samTemplatePath)) {
229-
return vscode.Uri.file(samTemplatePath)
227+
const cfnTemplatePath = path.resolve(config.location.fsPath, config.name, 'template.yaml')
228+
if (await fileExists(cfnTemplatePath)) {
229+
return vscode.Uri.file(cfnTemplatePath)
230230
} else {
231231
vscode.window.showWarningMessage(
232232
localize(
233233
'AWS.samcli.initWizard.source.error.notFound',
234234
'Project created successfully, but main source code file not found: {0}',
235-
samTemplatePath
235+
cfnTemplatePath
236236
)
237237
)
238238
}

src/lambda/local/debugConfiguration.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function getCodeRoot(
9292
if (!templateResource?.Properties) {
9393
return undefined
9494
}
95-
const fullPath = tryGetAbsolutePath(folder, templateInvoke.samTemplatePath)
95+
const fullPath = tryGetAbsolutePath(folder, templateInvoke.templatePath)
9696
const templateDir = path.dirname(fullPath)
9797
return pathutil.normalize(path.resolve(templateDir ?? '', templateResource?.Properties?.CodeUri))
9898
}
@@ -142,13 +142,13 @@ export function getTemplate(
142142
}
143143
const templateInvoke = config.invokeTarget as TemplateTargetProperties
144144
const cftRegistry = CloudFormationTemplateRegistry.getRegistry()
145-
const fullPath = tryGetAbsolutePath(folder, templateInvoke.samTemplatePath)
145+
const fullPath = tryGetAbsolutePath(folder, templateInvoke.templatePath)
146146
const cfnTemplate = cftRegistry.getRegisteredTemplate(fullPath)?.template
147147
return cfnTemplate
148148
}
149149

150150
/**
151-
* Gets the template resources object specified by the `samTemplateResource`
151+
* Gets the template resources object specified by the `logicalId`
152152
* field (if the config has `invokeTarget.target=template`).
153153
*/
154154
export function getTemplateResource(
@@ -161,17 +161,15 @@ export function getTemplateResource(
161161
const templateInvoke = config.invokeTarget as TemplateTargetProperties
162162
const cfnTemplate = getTemplate(folder, config)
163163
if (!cfnTemplate) {
164-
throw Error(`template not found (not registered?): ${templateInvoke.samTemplatePath}`)
164+
throw Error(`template not found (not registered?): ${templateInvoke.templatePath}`)
165165
}
166166
if (!cfnTemplate?.Resources) {
167-
throw Error(`no Resources in template: ${templateInvoke.samTemplatePath}`)
167+
throw Error(`no Resources in template: ${templateInvoke.templatePath}`)
168168
}
169-
const templateResource: CloudFormation.Resource | undefined = cfnTemplate?.Resources![
170-
templateInvoke.samTemplateResource!!
171-
]
169+
const templateResource: CloudFormation.Resource | undefined = cfnTemplate?.Resources![templateInvoke.logicalId!!]
172170
if (!templateResource) {
173171
throw Error(
174-
`template Resources object does not contain key '${templateInvoke.samTemplateResource}':` +
172+
`template Resources object does not contain key '${templateInvoke.logicalId}':` +
175173
` ${JSON.stringify(cfnTemplate?.Resources)}`
176174
)
177175
}

src/shared/debug/launchConfiguration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function getSamCodeTargets(launchConfig: LaunchConfiguration): CodeTargetPropert
110110
}
111111

112112
/**
113-
* Returns a Set containing the samTemplateResources from the launch.json file that the launch config is scoped to.
113+
* Returns a Set containing the logicalIds from the launch.json file that the launch config is scoped to.
114114
* @param launchConfig Launch config to check
115115
*/
116116
export function getReferencedTemplateResources(launchConfig: LaunchConfiguration): Set<string> {
@@ -119,9 +119,9 @@ export function getReferencedTemplateResources(launchConfig: LaunchConfiguration
119119

120120
return _(existingSamTemplateTargets)
121121
.filter(target =>
122-
pathutils.areEqual(folder?.uri.fsPath, target.samTemplatePath, launchConfig.scopedResource.fsPath)
122+
pathutils.areEqual(folder?.uri.fsPath, target.templatePath, launchConfig.scopedResource.fsPath)
123123
)
124-
.map(target => target.samTemplateResource)
124+
.map(target => target.logicalId)
125125
.thru(array => new Set(array))
126126
.value()
127127
}

src/shared/sam/debugger/awsSamDebugConfiguration.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export function isCodeTargetProperties(props: TargetProperties): props is CodeTa
4242
}
4343

4444
/**
45-
* Ensures that the `projectRoot` or `samTemplatePath` relative properties on
45+
* Ensures that the `projectRoot` or `templatePath` relative properties on
4646
* the given `config` are relative (not absolute) paths.
4747
*
48-
* @param folder Workspace folder, or empty to use the workspace associated with `projectRoot` or `samTemplatePath`.
48+
* @param folder Workspace folder, or empty to use the workspace associated with `projectRoot` or `templatePath`.
4949
* @param config
5050
*/
5151
export function ensureRelativePaths(
@@ -57,7 +57,7 @@ export function ensureRelativePaths(
5757
}
5858
const filepath =
5959
config.invokeTarget.target === TEMPLATE_TARGET_TYPE
60-
? config.invokeTarget.samTemplatePath
60+
? config.invokeTarget.templatePath
6161
: config.invokeTarget.projectRoot
6262
if (!path.isAbsolute(filepath)) {
6363
return
@@ -70,7 +70,7 @@ export function ensureRelativePaths(
7070
}
7171
const relPath = getNormalizedRelativePath(folder!.uri.fsPath, filepath)
7272
if (config.invokeTarget.target === TEMPLATE_TARGET_TYPE) {
73-
config.invokeTarget.samTemplatePath = relPath
73+
config.invokeTarget.templatePath = relPath
7474
} else {
7575
config.invokeTarget.projectRoot = relPath
7676
}
@@ -119,8 +119,8 @@ export function createTemplateAwsSamDebugConfig(
119119
name: makeName(resourceName, templateParentDir, runtimeName),
120120
invokeTarget: {
121121
target: TEMPLATE_TARGET_TYPE,
122-
samTemplatePath: workspaceRelativePath,
123-
samTemplateResource: resourceName,
122+
templatePath: workspaceRelativePath,
123+
logicalId: resourceName,
124124
},
125125
lambda: {
126126
event: {},

src/shared/sam/debugger/awsSamDebugConfigurationValidator.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ export class DefaultAwsSamDebugConfigurationValidator implements AwsSamDebugConf
5959
)
6060
} else if (config.invokeTarget.target === TEMPLATE_TARGET_TYPE) {
6161
let cfnTemplate
62-
if (config.invokeTarget.samTemplatePath) {
63-
const fullpath = tryGetAbsolutePath(this.workspaceFolder, config.invokeTarget.samTemplatePath)
62+
if (config.invokeTarget.templatePath) {
63+
const fullpath = tryGetAbsolutePath(this.workspaceFolder, config.invokeTarget.templatePath)
6464
// Normalize to absolute path for use in the runner.
65-
config.invokeTarget.samTemplatePath = fullpath
65+
config.invokeTarget.templatePath = fullpath
6666
cfnTemplate = this.cftRegistry.getRegisteredTemplate(fullpath)?.template
6767
}
68-
rv = this.validateTemplateConfig(config, config.invokeTarget.samTemplatePath, cfnTemplate)
68+
rv = this.validateTemplateConfig(config, config.invokeTarget.templatePath, cfnTemplate)
6969
} else if (config.invokeTarget.target === CODE_TARGET_TYPE) {
7070
rv = this.validateCodeConfig(config)
7171
}
@@ -95,7 +95,7 @@ export class DefaultAwsSamDebugConfigurationValidator implements AwsSamDebugConf
9595
message: localize(
9696
'AWS.sam.debugger.missingField',
9797
'Missing required field "{0}" in debug config',
98-
'samTemplatePath'
98+
'templatePath'
9999
),
100100
}
101101
}
@@ -106,36 +106,36 @@ export class DefaultAwsSamDebugConfigurationValidator implements AwsSamDebugConf
106106
message: localize(
107107
'AWS.sam.debugger.missingTemplate',
108108
'Invalid (or missing) template file (path must be workspace-relative, or absolute): {0}',
109-
templateTarget.samTemplatePath
109+
templateTarget.templatePath
110110
),
111111
}
112112
}
113113

114114
const resources = cfnTemplate.Resources
115-
if (!templateTarget.samTemplateResource) {
115+
if (!templateTarget.logicalId) {
116116
return {
117117
isValid: false,
118118
message: localize(
119119
'AWS.sam.debugger.missingField',
120120
'Missing required field "{0}" in debug config',
121-
'samTemplateResource'
121+
'logicalId'
122122
),
123123
}
124124
}
125125

126-
if (!resources || !Object.keys(resources).includes(templateTarget.samTemplateResource)) {
126+
if (!resources || !Object.keys(resources).includes(templateTarget.logicalId)) {
127127
return {
128128
isValid: false,
129129
message: localize(
130130
'AWS.sam.debugger.missingResource',
131131
'Cannot find the template resource "{0}" in template file: {1}',
132-
templateTarget.samTemplateResource,
133-
templateTarget.samTemplatePath
132+
templateTarget.logicalId,
133+
templateTarget.templatePath
134134
),
135135
}
136136
}
137137

138-
const resource = resources[templateTarget.samTemplateResource]
138+
const resource = resources[templateTarget.logicalId]
139139

140140
// TODO: Validate against `AWS::Lambda::Function`?
141141
if (resource?.Type !== CloudFormation.SERVERLESS_FUNCTION_TYPE) {
@@ -144,8 +144,8 @@ export class DefaultAwsSamDebugConfigurationValidator implements AwsSamDebugConf
144144
message: localize(
145145
'AWS.sam.debugger.resourceNotAFunction',
146146
'Template Resource {0} in Template file {1} needs to be of type {2}',
147-
templateTarget.samTemplateResource,
148-
templateTarget.samTemplatePath,
147+
templateTarget.logicalId,
148+
templateTarget.templatePath,
149149
CloudFormation.SERVERLESS_FUNCTION_TYPE
150150
),
151151
}
@@ -157,8 +157,8 @@ export class DefaultAwsSamDebugConfigurationValidator implements AwsSamDebugConf
157157
message: localize(
158158
'AWS.sam.debugger.unsupportedRuntime',
159159
'Runtime for Template Resource {0} in Template file {1} is either undefined or unsupported.',
160-
templateTarget.samTemplateResource,
161-
templateTarget.samTemplatePath
160+
templateTarget.logicalId,
161+
templateTarget.templatePath
162162
),
163163
}
164164
}

src/shared/sam/debugger/awsSamDebugger.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface SamLaunchRequestArgs extends AwsSamDebuggerConfiguration {
9090
* - For `target=template` this is the _generated_ template path (TODO: in
9191
* the future we may change this to be the template found in the workspace.
9292
*/
93-
samTemplatePath: string
93+
templatePath: string
9494

9595
/**
9696
* Path to the (generated) `event.json` file placed in `baseBuildDir` for SAM to discover.
@@ -290,12 +290,10 @@ export class SamDebugConfigProvider implements vscode.DebugConfigurationProvider
290290
const codeRoot = getCodeRoot(folder, config)
291291
const handlerName = getHandlerName(folder, config)
292292

293-
if (templateInvoke?.samTemplatePath) {
293+
if (templateInvoke?.templatePath) {
294294
// Normalize to absolute path.
295295
// TODO: If path is relative, it is relative to launch.json (i.e. .vscode directory).
296-
templateInvoke.samTemplatePath = pathutil.normalize(
297-
tryGetAbsolutePath(folder, templateInvoke.samTemplatePath)
298-
)
296+
templateInvoke.templatePath = pathutil.normalize(tryGetAbsolutePath(folder, templateInvoke.templatePath))
299297
}
300298

301299
const runtime: string | undefined =
@@ -318,7 +316,7 @@ export class SamDebugConfigProvider implements vscode.DebugConfigurationProvider
318316
const documentUri =
319317
vscode.window.activeTextEditor?.document.uri ??
320318
// XXX: don't know what URI to choose...
321-
vscode.Uri.parse(templateInvoke.samTemplatePath!!)
319+
vscode.Uri.parse(templateInvoke.templatePath!!)
322320

323321
let awsCredentials: Credentials | undefined
324322

@@ -342,7 +340,7 @@ export class SamDebugConfigProvider implements vscode.DebugConfigurationProvider
342340
runtimeFamily: runtimeFamily,
343341
handlerName: handlerName,
344342
documentUri: documentUri,
345-
samTemplatePath: pathutil.normalize(templateInvoke?.samTemplatePath),
343+
templatePath: pathutil.normalize(templateInvoke?.templatePath),
346344
eventPayloadFile: '', // Populated by makeConfig().
347345
envFile: '', // Populated by makeConfig().
348346
debugPort: config.noDebug ? undefined : await getStartPort(),

0 commit comments

Comments
 (0)