aws / aws/aws-sam-cli

Bug: Is there a way to supply overrides for non-specified environment variables when using with terraform

Open
#5,822 5 comments 0 reactions 0 assignees View on GitHub
area/terraform blocked/more-info-needed stage/closed-for-inactivity
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:

We use the module pattern in terraform, which leads to most resources having a sort of wrapper. As a result, our environment variables are a bit abstracted like this:

```
resource "aws_lambda_function" "this" {
...
environment {
variables = var.environment.variables
}
...
}
```

The command `sam build` expectedly won't pick up these variables, so they don't get into the generated template.json file, and I think thats fine. The next problem is that `sam local invoke xyz` won't allow me to inject these dynamic environment variables into the runtime. At least, `--env-vars` doesn't seem to be able to actually inject environment variables. Is there something I'm missing?

### Steps to reproduce:

1. Have a lambda within a module with environment variables supplied as a `map(string)` type variable to the module.
2. `sam build; sam local invoke xyz --env-vars env.json`
3. The environment variables needed won't work here.

### Observed result:

None of the env vars under Parameters are injected.

### Expected result:

I would expect the env-vars under Parameters to be injected as environment variables.

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

```
{
"version": "1.95.0",
"system": {
"python": "3.8.13",
"os": "macOS-13.4.1-arm64-arm-64bit"
},
"additional_dependencies": {
"docker_engine": "24.0.2",
"aws_cdk": "Not available",
"terraform": "1.4.6"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.