Skip to main content

atmos env

Output environment variables from the env section of atmos.yaml in various formats suitable for shell evaluation, .env files, JSON consumption, or GitHub Actions workflows.

atmos env --help

Usage

atmos env [--format bash|json|dotenv|github] [--output <file>]

How It Works

The atmos env command reads the env section from your atmos.yaml configuration (including any active profiles) and outputs the environment variables in your chosen format. This is useful for:

  • Exporting Atmos-configured environment variables to your shell
  • Generating .env files for other tools
  • Integrating with CI/CD pipelines, especially GitHub Actions
  • Inspecting what environment variables Atmos will set

Examples

Shell Evaluation

Load environment variables into your current shell:

# Load env vars into current shell
eval $(atmos env)

# Now tools like Terraform can use GITHUB_TOKEN, TF_PLUGIN_CACHE_DIR, etc.
terraform init

Using with Profiles

Profiles are automatically applied when specified:

# Use CI profile
eval $(atmos env --profile ci)

# Or via environment variable
ATMOS_PROFILE=ci eval $(atmos env)

GitHub Actions Integration

Write environment variables directly to GitHub Actions:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Atmos
uses: cloudposse/github-action-atmos@v2

- name: Export Atmos environment
run: atmos env --format github

- name: Use environment variables
run: |
echo "GitHub token available for private modules"
terraform init

The --format github option automatically writes to the $GITHUB_ENV file. You can also specify a custom output file:

# Write to custom file
atmos env --format github --output /tmp/my-env

# In GitHub Actions, use the default $GITHUB_ENV
atmos env --format github

Generate .env File

Create a .env file for tools that support it:

atmos env --format dotenv --output .env

JSON Output

Get environment variables as JSON for programmatic use:

atmos env --format json | jq .GITHUB_TOKEN

Output Formats

FormatOutput ExampleUse Case
bash (default)export KEY='value'Shell evaluation with eval $(atmos env)
dotenvKEY='value'.env files for Docker, direnv, etc.
json{"KEY": "value"}Programmatic consumption with jq, scripts
githubKEY=valueGitHub Actions $GITHUB_ENV file

Format Details

bash (default): Shell export statements with proper escaping for single quotes.

export GITHUB_TOKEN='ghp_xxxx'
export TF_PLUGIN_CACHE_DIR='/tmp/terraform-plugin-cache'

dotenv: Standard .env file format.

GITHUB_TOKEN='ghp_xxxx'
TF_PLUGIN_CACHE_DIR='/tmp/terraform-plugin-cache'

json: JSON object for programmatic use.

{
"GITHUB_TOKEN": "ghp_xxxx",
"TF_PLUGIN_CACHE_DIR": "/tmp/terraform-plugin-cache"
}

github: GitHub Actions environment file format. Multiline values use heredoc syntax.

GITHUB_TOKEN=ghp_xxxx
TF_PLUGIN_CACHE_DIR=/tmp/terraform-plugin-cache

Flags

--format, -f

Output format for the environment variables. Default: bash.

  • bash (default): Prints export KEY='value' lines suitable for shell evaluation
  • dotenv: Prints KEY='value' lines in dotenv format
  • json: Prints a JSON object of environment variables
  • github: Prints KEY=value lines for GitHub Actions $GITHUB_ENV file
--output, -o

Output file path. When specified, writes to the file instead of stdout.

For --format github, if --output is not specified, the command reads the GITHUB_ENV environment variable and writes to that file. If GITHUB_ENV is not set, an error is returned.

For other formats, if --output is not specified, output goes to stdout.

Configuration

Environment variables are configured in the env section of atmos.yaml:

atmos.yaml

env:
# Dynamic values using YAML functions
GITHUB_TOKEN: !exec gh auth token

# Static values
AWS_SDK_LOAD_CONFIG: "true"
TF_PLUGIN_CACHE_DIR: /tmp/terraform-plugin-cache

Configure Environment Variables

Learn how to define global environment variables in your atmos.yaml using static values, YAML functions, and shell expansion.

Notes

  • Environment variables are sorted alphabetically in the output for deterministic results
  • The github format appends to the output file (doesn't overwrite), following GitHub Actions conventions
  • Shell escaping is applied for bash and dotenv formats (single quotes with ' escaped as '\'')
  • Profile merging happens automatically - use --profile or ATMOS_PROFILE to select a profile
  • This command only outputs global env from atmos.yaml, not component-level env from stacks

See Also