AWS Elastic Beanstalk app crashes after deploy: .env file not deployed
Problem
.env is listed in .gitignore and is not included in the deployment package uploaded to Elastic Beanstalk. The application starts but immediately crashes because all environment variables (database URLs, API keys, secrets) are undefined. EB environment variables must be explicitly configured in the EB console or .ebextensions — they are not read from .env files.
Error Output
Error: DATABASE_URL is not defined
at Object.<anonymous> (/var/app/current/src/db.js)Unverified for your environment
Select your OS to check compatibility.
1 Fix
Set all required environment variables in Elastic Beanstalk configuration
.env files are gitignored and not included in deployment packages. EB reads environment variables from its own environment configuration, not from .env files.
Trust Score
4 verifications
- 1
List all required env vars from your .env file
Copy every variable from your local .env file (do not copy the values to any shared system).
- 2
Add them in EB Console
AWS Console → Elastic Beanstalk → Environment → Configuration → Software → Edit → Environment Properties → add each variable.
- 3
Or set via AWS CLI in bulk
Use the CLI to set multiple env vars at once:
bashaws elasticbeanstalk update-environment \ --environment-name your-env-name \ --option-settings \ Namespace=aws:elasticbeanstalk:application:environment,OptionName=DATABASE_URL,Value="postgresql://..." \ Namespace=aws:elasticbeanstalk:application:environment,OptionName=SECRET_KEY,Value="..." - 4
Verify after deployment
SSH into the EB instance and run `printenv | grep YOUR_VAR` or add a health check endpoint that returns the ENV name.
Validation
Application starts and all features work after deployment. Health endpoint confirms expected ENV value.
Verification Summary
Sign in to verify this fix
Environment
- Product
- AWS Elastic Beanstalk
- Environment
- production
Submitted by
Alex Chen
2450 rep