sam --env-vars accepts .env file format
Introduced 2026-03-19 · score 0.97
HOW TO USE IT
When setting local environment variables for SAM, put global `KEY=value` entries in a `.env` file, then pass its path to `sam local invoke` or `sam local start-api` with `--env-vars`.
sam local invoke --env-vars .envsam local start-api --env-vars .envWHY THIS HELPS
Set environment variables for a local SAM workflow using a .env file.
REQUIREMENTS AND LIMITATIONS
- Version: v1.156.0
- --env-vars, -n <PATH>: Path to a JSON or `.env` file with Lambda environment variable values; format is detected automatically. `.env` values apply globally; function-specific overrides require JSON.
- Prerequisite: Create a `.env` file with `KEY=value` lines. Comments starting with `#` and quoted values are supported; `.env` files only support global variables.
FIRST-PARTY EVIDENCE
- https://github.com/aws/aws-sam-cli/releases/tag/v1.156.0
- https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-invoke.html
- https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-invoke.html
Check the installed version and the source before using it. Entry JSON