Skip to content

Commit a0ce4db

Browse files
authored
Merge #1149 'SAM debugconfig: rename some fields'
2 parents d405e4e + 11d0f13 commit a0ce4db

19 files changed

+175
-179
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ 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",
183-
"samTemplateResource": "HelloWorldResource" // Name of Template resource to debug
182+
"templatePath": "path to template yaml file",
183+
"logicalId": "HelloWorldResource" // Name of Template resource to debug
184184
},
185185
// Lambda Execution related arguments
186186
"lambda": {
@@ -190,7 +190,7 @@ The required fields are: type, request, invokeTarget
190190
"envvar2": "..."
191191
},
192192
// The event passed to the Lambda handler (defaults to an empty JSON object)
193-
"event": {
193+
"payload": {
194194
// path or json, not both
195195
"path": "somepath", // Path to event data
196196
"json": {
@@ -256,7 +256,7 @@ The required fields are: type, request, invokeTarget, lambda.runtime
256256
"envvar2": "..."
257257
},
258258
// The event passed to the Lambda handler (defaults to an empty JSON object)
259-
"event": {
259+
"payload": {
260260
// path or json, not both
261261
"path": "somepath", // Path to event data
262262
"json": {

package.json

Lines changed: 12 additions & 11 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"
@@ -238,10 +238,11 @@
238238
},
239239
"type": "object"
240240
},
241-
"event": {
241+
"payload": {
242242
"description": "%AWS.configuration.description.awssam.debug.event%",
243243
"properties": {
244244
"json": {
245+
"description": "%AWS.configuration.description.awssam.debug.event.json%",
245246
"additionalProperties": {
246247
"type": [
247248
"string",
@@ -347,7 +348,7 @@
347348
},
348349
"lambda": {
349350
"runtime": "${2:Lambda Runtime}",
350-
"event": {
351+
"payload": {
351352
"json": {}
352353
}
353354
}
@@ -362,11 +363,11 @@
362363
"name": "${3:Invoke Lambda}",
363364
"invokeTarget": {
364365
"target": "template",
365-
"samTemplatePath": "${1:Template Location}",
366-
"samTemplateResource": "${2:Function Logical ID}"
366+
"templatePath": "${1:Template Location}",
367+
"logicalId": "${2:Function Logical ID}"
367368
},
368369
"lambda": {
369-
"event": {
370+
"payload": {
370371
"json": {}
371372
}
372373
}

package.nls.json

Lines changed: 8 additions & 7 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.",
@@ -70,9 +70,9 @@
7070
"AWS.configuration.description.awssam.debug.aws": "AWS connection details",
7171
"AWS.configuration.description.awssam.debug.credentials": "The AWS credential type and ID to use during the invocation. Example: credential profile \"default\" would be entered as `profile:default`.",
7272
"AWS.configuration.description.awssam.debug.region": "AWS region to use during the invocation.",
73-
"AWS.configuration.description.awssam.debug.event": "The payload to pass to the lambda invocation.\n Must specify one of 'json' or 'path'.",
74-
"AWS.configuration.description.awssam.debug.event.json": "A JSON document to use as the event payload",
75-
"AWS.configuration.description.awssam.debug.event.path": "The path to a file to use as the event payload",
73+
"AWS.configuration.description.awssam.debug.event": "Event payload to pass to the Lambda invocation.\n Must specify one of 'json' or 'path'.",
74+
"AWS.configuration.description.awssam.debug.event.json": "JSON definition to use as the event payload",
75+
"AWS.configuration.description.awssam.debug.event.path": "Path to a file to use as the event payload",
7676
"AWS.configuration.description.awssam.debug.sam": "SAM CLI specific configurations",
7777
"AWS.configuration.description.awssam.debug.buildArguments": "Additional arguments to pass to the `sam build` command.",
7878
"AWS.configuration.description.awssam.debug.containerBuild": "Whether to build inside a container (default: false).",
@@ -248,7 +248,8 @@
248248
"AWS.output.sam.local.attach.failure": "Unable to attach Debugger. Check the Terminal tab for output. If it took longer than expected to successfully start, you may still attach to it.",
249249
"AWS.output.sam.local.attach.retry.limit.exceeded": "Retry limit reached while trying to attach the debugger.",
250250
"AWS.output.sam.local.error": "Error: {0}",
251-
"AWS.output.sam.local.start": "Preparing to run {0} locally...",
251+
"AWS.output.sam.local.startRun": "Preparing to run '{0}' locally...",
252+
"AWS.output.sam.local.startDebug": "Preparing to debug '{0}' locally...",
252253
"AWS.output.sam.local.waiting": "Waiting for SAM Application to start before attaching debugger...",
253254
"AWS.output.starting.sam.app.locally": "Starting the SAM Application locally (see Terminal for output)",
254255
"AWS.prompt.mfa.enterCode.placeholder": "Enter Authentication Code Here",

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: 10 additions & 10 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,11 +119,11 @@ 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: {
126-
event: {},
126+
payload: {},
127127
environmentVariables: {},
128128
},
129129
}
@@ -134,11 +134,11 @@ export function createTemplateAwsSamDebugConfig(
134134
lambda:
135135
preloadedConfig.environmentVariables || preloadedConfig.eventJson
136136
? {
137-
event: preloadedConfig.eventJson ? { json: preloadedConfig.eventJson } : {},
137+
payload: preloadedConfig.eventJson ? { json: preloadedConfig.eventJson } : {},
138138
environmentVariables: preloadedConfig.environmentVariables,
139139
}
140140
: {
141-
event: {},
141+
payload: {},
142142
environmentVariables: {},
143143
},
144144
sam:
@@ -174,7 +174,7 @@ export function createCodeAwsSamDebugConfig(
174174
},
175175
lambda: {
176176
runtime,
177-
event: {},
177+
payload: {},
178178
environmentVariables: {},
179179
},
180180
}

0 commit comments

Comments
 (0)