Skip to main content

Environment Variables

Manage environment variables for your deployed Lambda functions directly from the CLI.

Overview

The leanmcp env command provides a complete set of tools for managing environment variables on your running Lambda deployments. Changes are applied immediately (causing a cold start on next invocation).
System variables like PORT, AWS_LWA_* cannot be modified or deleted as they are required for Lambda Web Adapter.

List Environment Variables

View all environment variables for your deployment:

Options

Examples

Example Output:
With —reveal:

Set Environment Variable

Add or update an environment variable:

Options

Examples

Example Output:
Variable keys are automatically converted to uppercase and sanitized to match Lambda environment variable naming rules.

Get Environment Variable

Retrieve a specific environment variable:

Options

Examples

Example Output:
With —reveal:

Remove Environment Variable

Delete an environment variable:

Options

Examples

Example Output:
This action cannot be undone. The variable will be permanently deleted from your Lambda function.

Pull Environment Variables

Download environment variables to a local .env file:

Options

Examples

Example Output:
Generated .env file:

Push Environment Variables

Upload environment variables from a local .env file:

Options

Examples

Example Output (Merge Mode):
Example Output (Replace Mode):
In --replace mode, all existing user variables will be deleted and replaced with the contents of your file. System variables are always preserved.

Full Workflow Example

Complete workflow for managing environment variables:

Protected Variables

The following variables are protected and cannot be modified: AWS Reserved:
  • AWS_* (all AWS-prefixed variables)
Lambda Web Adapter System:
  • PORT
  • AWS_LWA_PORT
  • AWS_LWA_INVOKE_MODE
  • AWS_LWA_READINESS_CHECK_MIN_UNHEALTHY_STATUS
These variables are automatically managed by AWS Lambda and the Lambda Web Adapter. Attempting to modify them will result in them being skipped with a warning.

Troubleshooting

Not Authenticated

Solution: Run leanmcp login and enter your API key.

No Deployment Found

Solution: Deploy your project first using leanmcp deploy .

Variable Name Validation

Solution: Use only uppercase letters, numbers, and underscores. Must start with a letter.

File Not Found

Solution: Ensure the .env file exists or specify a different file with --file.

Parse Error

Solution: Ensure your .env file uses KEY=VALUE format (one per line).

Next Steps

Deploy Projects

Deploy your MCP server to the cloud

Monitor Deployments

View deployment status and logs