sst / ion

SST v3
https://sst.dev
MIT License
1.53k stars 195 forks source link

Feature request: configure dotenv files in sst.config.ts #796

Open chrisandrewcl opened 1 month ago

chrisandrewcl commented 1 month ago

As with v0.1.72, ion behavior for dotenv files seems to be:

  1. Sst loads variables from .env and .env.{stage} if they are available (respectively, so .env values will take precedence)
  2. Only dotenv files in the same folder as sst.config.ts are loaded (usually, the root of the project).

It would be great to be able to override this behavior in the app block of the sst.config.ts. This way the user can load any dotfiles they want, in any order and location, or not load any at all (e.g. by specifying an empty array or null/false).

Also, for those interested in more details, since it doesn't seem to be documented yet:

  1. This behavior is true even if sst is run in subdirectories.
  2. The values loaded are made available for the sst.config.ts but are not passed to child processes (e.g. code run with sst dev, built/deployed with sst deploy, or run with sst shell).
  3. To inject env vars in child processes, they must be specified in the environments argument of the relevant components (e.g. StaticSite, Function, DevCommand, etc.).
  4. Also relevant: AWS_PROFILE is not injected in child processes, instead SST injects temporary credentials generated with the profile.
jayair commented 1 month ago

Hmm I didn't get .env.{stage} to work. https://github.com/sst/ion/issues/803

EDIT: False alarm it works