To automatically load environment variables from .env files (with the help of the dotenv package), set useDotenv: true in serverless.yml:
useDotenv: trueWith that option enabled, .env files will also be excluded from the package in order to avoid uploading sensitive data as a part of a package by mistake.
osls loads .env.{stage} from the service directory when present; otherwise it falls back to .env. If stage is not explicitly defined, it defaults to dev. Invalid stage names are rejected before .env.{stage} is read.
osls loads .env files quietly by default. Avoid DOTENV_CONFIG_DEBUG=true or DOTENV_CONFIG_QUIET=false when using machine-readable commands such as serverless print, or when using osls compose, because those dotenv options can write runtime loading messages to stdout.
It is possible to define environment variables as a combination of existing ones:
BASE_URL=my.api.com
PROTOCOL=https
URL=$PROTOCOL/$BASE_URLThis is supported through dotenv-expand
There are a few differences between above functionality and serverless-dotenv-plugin:
- osls only loads environment variables locally and does not pass them to your function's environment
- osls loads variables from only one
.envfile (if stage-specific.envis found, default.envis not loaded) - osls does not support
.env.local,.env.{stage}.local, and.env.developmentfiles in a similar way to the plugin - osls does not use
NODE_ENVvariable and--envflag when determining stage