aws / aws/aws-toolkit-vscode

SAM: use 'environmentVariables' without adding them to the template

Open
#2,037 2 comments 0 reactions 0 assignees View on GitHub
bug documentation sam ux
Dominant language
TypeScript
Stars
2k
Forks
807
Avg merge
10h 12m
Merged PRs (30d)
7

Description

**Describe the bug**

Developers need to be able to specify environment variables for debugging Lambda functions.

I tried specifying those values in `lambda.environmentVariables` (seen below) with no luck. My workaround was to add them to the template.yaml, but that is not very flexible or natural when working with VS Code debug configurations.

All documentation I can find leaves `lambda.environmentVariables` an empty object. For example, [here](https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps-run-debug-config-ref.html).

The toolkit generated this `.vscode/launch.json` for me:

```jsonc
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "lambda-nodejs:Function",
"invokeTarget": {
"target": "template",
"templatePath": "${workspaceFolder}/template.yaml",
"logicalId": "Function"
},
"lambda": {
"payload": {"path": "src/test/events/my.json"},
"environmentVariables": {
"key": "value"
},
}
}
]
}
```

**To Reproduce**

Steps to reproduce the behavior:
1. use the toolkit to add a debug configuration for lambda functions
2. specify environment variables with custom keys
3. read the environment variable key in your code (nodejs for me)
4. notice the key gives no value.

**Expected behavior**

I expect the debugging context to allow code to read from `process.env.key` where `key` is any key specified in the debug configuration `lambda.environmentVariables`.

**Desktop (please complete the following information):**

- OS: Darwin x64 19.6.0
- Visual Studio Code Extension Host Version: 1.60.1
- AWS Toolkit Version: 1.29.0

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the .vscode/launch.json configuration shown, then trace how lambda.environmentVariables is handled during the SAM direct-invoke debug flow. Done means a configured key is available through process.env.key without adding it to template.yaml; verify this with the reproduction steps.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, nodejs, typescript, vscode
Domain
developer-experience, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.