Skip to content

Commit 02d21a2

Browse files
authored
fix(appbuilder): Update support for enVar in the webview (#6413)
## Problem Update support for enVar in the webview --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent fb5bace commit 02d21a2

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

packages/core/src/awsService/appBuilder/explorer/samProject.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export interface ResourceTreeEntity {
3030
Events?: ResourceTreeEntity[]
3131
Path?: string
3232
Method?: string
33+
Environment?: {
34+
Variables: Record<string, any>
35+
}
3336
}
3437

3538
export async function getStackName(projectRoot: vscode.Uri): Promise<any> {
@@ -81,10 +84,10 @@ function getResourceEntity(template: any): ResourceTreeEntity[] {
8184
Handler: resource.Properties?.Handler ?? template?.Globals?.Function?.Handler,
8285
Events: resource.Properties?.Events ? getEvents(resource.Properties.Events) : undefined,
8386
CodeUri: resource.Properties?.CodeUri ?? template?.Globals?.Function?.CodeUri,
87+
Environment: resource.Properties?.Environment ?? template?.Globals?.Function?.Environment,
8488
}
8589
resourceTree.push(resourceEntity)
8690
}
87-
8891
return resourceTree
8992
}
9093

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export interface ResourceData {
4646
runtime: string
4747
stackName: string
4848
source: string
49+
environment?: {
50+
Variables: Record<string, any>
51+
}
4952
}
5053

5154
export type AwsSamDebuggerConfigurationLoose = AwsSamDebuggerConfiguration & {
@@ -441,6 +444,7 @@ export async function registerSamDebugInvokeVueCommand(
441444
runtime: resource.resource.Runtime!,
442445
arn: resource.functionArn ?? '',
443446
stackName: resource.stackName ?? '',
447+
environment: resource.resource.Environment,
444448
source: source,
445449
})
446450
await telemetry.sam_openConfigUi.run(async (span) => {

packages/core/src/lambda/vue/configEditor/samInvokeComponent.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
debugger to the code running in a local Docker container. open
3030
<a href="#" @click.prevent="openLaunchJson">launch.json</a>.<br />
3131
<br />
32-
<strong>Note:</strong> If you are accessing environment variables in your function code, ensure you
33-
input them in the "Additional fields -> Lambda -> Environment variables" section, following JSON
34-
format:<code>{"KEY":"VALUE"}</code>
3532
</em>
3633
</p>
3734
<settings-panel id="config-panel" title="General configuration" description="" :start-collapsed="false">

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ export default defineComponent({
345345
this.launchConfig.invokeTarget.lambdaHandler = this.resourceData.handler
346346
if (this.launchConfig.lambda) {
347347
this.launchConfig.lambda.runtime = this.resourceData.runtime
348+
if (this.resourceData.environment?.Variables !== undefined) {
349+
this.environmentVariables.value = JSON.stringify(
350+
this.resourceData.environment?.Variables
351+
)
352+
}
348353
}
349354
}
350355
},

packages/core/src/test/lambda/vue/samInvokeBackend.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,9 @@ describe('SamInvokeWebview', () => {
728728
},
729729
lambda: {
730730
runtime: 'python3.9',
731+
environmentVariables: {
732+
PARAM1: 'VALUE',
733+
},
731734
},
732735
sam: {
733736
containerBuild: false,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Lambda: Support for environment variables in the editor webview."
4+
}

0 commit comments

Comments
 (0)