How should I inject env vars with sam build

Viewed 944

I am using AWS SAM.
I have created a samconfig.toml file with the following entry:

[default.build.parameters]
container_env_var_file = "envDefault.json"

When I do sam build I see in .aws-sam/build.toml The env values from envDefault.json
But when I check the template .aws-sam/build/template.yaml I see the original values, not the overwrites I have in envDefault.json

What is the best way to sam deploy with overwrites of the env variables for each environment I am deploying to?
I am trying to avoid entering parameters manually during the deploy process.

1 Answers

It seems you are trying to set build parameters not deploy parameters.

All the build parameters section in AWS SAM toml file starts with, [default.build.parameters]

And for the overriding deployment parameters, you have to use [default.deploy.parameters] section (default denotes the default profile).

So in your case, it will be like this.

[default.deploy.parameters]
parameter_overrides = "ParamKey=\"ParamValue\""

or you can use command line,

sam deploy --parameter-overrides

But if you are trying to get some values for your lambda functions based on environment, I strongly suggest the usage of parameter store.

Related