Skip to content

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

Open
@cyrfer

Description

@cyrfer

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.

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

{
  "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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugWe can reproduce the issue and confirmed it is a bug.documentationsamuxuser experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions