generate-env
Reads a .env.<Environment> file and writes .env, optionally merging in CloudFormation outputs from other deployed packages.
Usage
carlin generate-env
By default this reads .env.Staging and writes .env. The environment is resolved from the --environment flag, falling back to --default-environment (default: Staging).
Options
| Option | Alias | Default | Description |
|---|---|---|---|
--default-environment | -d | Staging | Fallback environment name when --environment is not set |
--path | -p | ./ | Directory where .env.<Environment> source files are looked up |
Merging Outputs from Other Packages
In a monorepo it is common for one package to need outputs from a stack deployed by another package (e.g. a frontend app needing the AppSync URL from a backend API package). Use envFromDeployOutputs in carlin.yml to map those outputs into your .env file.
# carlin.yml
envFromDeployOutputs:
- dir: ../graph-api # relative path to the other package
variables:
VITE_APPSYNC_GRAPHQL_ENDPOINT: AppSyncApiGraphQLUrl.OutputValue
VITE_APPSYNC_CONSOLE_URL: AppSyncApiGraphQLUrl.ExportName
Each entry under envFromDeployOutputs reads .carlin/latest-deploy.json inside dir (written by carlin deploy). The variable value is a dot-notation path into the outputs object:
AppSyncApiGraphQLUrl— shorthand forAppSyncApiGraphQLUrl.OutputValueAppSyncApiGraphQLUrl.OutputValue— explicit field selectionAppSyncApiGraphQLUrl.ExportName— any other field on the output object
If the file cannot be read, or the specified output key/field does not exist, a warning is logged and that variable is skipped.
Deploy output variables are merged into the generated .env. If a key from envFromDeployOutputs already exists in .env.<Environment>, the deploy output value wins — the static value is removed. This lets you commit a sensible default in .env.Staging and have the real deployed value override it automatically.
# .env.Staging (source)
EXISTING_VAR=from-env-staging-file
VITE_APPSYNC_GRAPHQL_ENDPOINT=https://static-placeholder.example.com/graphql
# .env (generated)
EXISTING_VAR=from-env-staging-file
VITE_APPSYNC_GRAPHQL_ENDPOINT=https://wlzbneunwjctrddgrvlllm.appsync-api.us-east-1.amazonaws.com/graphql
VITE_APPSYNC_CONSOLE_URL=MyStack:AppSyncApiGraphQLUrl
Disabling Deploy Outputs for a Specific Environment
You can set envFromDeployOutputs: null under a specific environment in carlin.yml to skip deploy output resolution entirely for that environment. This is useful when a particular environment (e.g. Production) should always use values baked into the static .env.Production file rather than pulling live stack outputs.
# carlin.yml
envFromDeployOutputs:
- dir: ../graph-api
variables:
VITE_APPSYNC_GRAPHQL_ENDPOINT: AppSyncApiGraphQLUrl.OutputValue
environments:
Staging:
cloudfront: true
Production:
cloudfront: true
envFromDeployOutputs: null # disables deploy output resolution for Production
When carlin generate-env --environment Production runs, it reads .env.Production as normal but does not attempt to read any latest-deploy.json files. The generated .env contains only the static values from .env.Production.