Skip to content

Commit ffa544b

Browse files
authored
fix(lambda): [Getting Started] wrong template path after saving Debug Configs
## Problem The issue occurs when working with two projects that have separate `template.yaml` files in the workspace. When opening the Local Invoke config for template1, and then selecting a resource from template2, the template path changes to template2. After clicking the "Save Debug Config" button, the template path changes back to template1 when revisiting the config page. This behavior is unexpected, as the template path should not change after saving the debug configuration. ## Solution The issue was caused by the way the Local Invoke page loads and updates the resource fields. When the user opens the Local Invoke page, the backend function `getResourceData` is called to populate the fields with the initial resource data. However, when the user selects a resource from a different template (e.g., template2), the fields are updated accordingly. But when the user returns to the Local Invoke page, the `getResourceData` function is called again, and it populates the fields with the resource data from the initial template (template1). To address this, the solution is to add a check before running the `getResourceData` function. If the fields are already populated, there's no need to update them again with the initial resource data. This will prevent the unexpected change in the template path after saving the debug configuration.
1 parent 4d4145c commit ffa544b

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

packages/core/src/lambda/vue/configEditor/samInvokeFrontend.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -335,22 +335,24 @@ export default defineComponent({
335335
}
336336
)
337337

338-
client.getResourceData().then(
339-
(data) => {
340-
this.resourceData = data
341-
if (this.launchConfig && this.resourceData) {
342-
this.launchConfig.invokeTarget.logicalId = this.resourceData.logicalId
343-
this.launchConfig.invokeTarget.templatePath = this.resourceData.location
344-
this.launchConfig.invokeTarget.lambdaHandler = this.resourceData.handler
345-
if (this.launchConfig.lambda) {
346-
this.launchConfig.lambda.runtime = this.resourceData.runtime
338+
if (this.launchConfig.invokeTarget.templatePath === '') {
339+
client.getResourceData().then(
340+
(data) => {
341+
this.resourceData = data
342+
if (this.launchConfig && this.resourceData) {
343+
this.launchConfig.invokeTarget.logicalId = this.resourceData.logicalId
344+
this.launchConfig.invokeTarget.templatePath = this.resourceData.location
345+
this.launchConfig.invokeTarget.lambdaHandler = this.resourceData.handler
346+
if (this.launchConfig.lambda) {
347+
this.launchConfig.lambda.runtime = this.resourceData.runtime
348+
}
347349
}
350+
},
351+
(e) => {
352+
console.error('client.getResourceData failed: %s', (e as Error).message)
348353
}
349-
},
350-
(e) => {
351-
console.error('client.getResourceData failed: %s', (e as Error).message)
352-
}
353-
)
354+
)
355+
}
354356

355357
client.getRuntimes().then(
356358
(runtimes) => {

0 commit comments

Comments
 (0)