Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

382
Views
aws eb deploy doesn't load environment variables

I'm deploying symfony project via eb deploy to ec2 instance (aws linux 2). Post deploy migrations scripts works well, but then I try to run symfony command with ec2-user I get an error about wrong database credentials. It is because I have pushed dump .env file with empty values. All my enviroment variables are stored in eb -> configuration -> Environment properties. How to make these variables to be visible to other users to properly execute commands?

I can see these variables as json with:

/opt/elasticbeanstalk/bin/get-config environment
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The EB env variables on Amazon Linux 1 are stored in:

/opt/elasticbeanstalk/support/envvars

Thus, to load them when you login to the instance you can do the following:

source /opt/elasticbeanstalk/support/envvars

To check if they got loaded, you can just execute:

env

p.s.

For Amazon Linux 2:

export $(cat /opt/elasticbeanstalk/deployment/env | xargs)
over 4 years ago · Santiago Trujillo Report

0

I stumbled on the same issue, this documentation shed some light on how to fix permission issues in Amazon Linux 2 although it is not straightforward.

over 4 years ago · Santiago Trujillo Report

0

Something to note, is that the answer provided by @Marcin will fail if implemented in a deployment script within the .ebextensions or .platform folders on new instance deployments.

In order to properly retrieve the environment variables, and source them to the shell, AWS has an article outlining how this is done:

https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-env-variables-shell/

For future reference, here are the instructions copied from the AWS docs:

Resolution

  1. Create a .ebextension file in your application source bundle and include the following:
commands:
    setvars:
        command: /opt/elasticbeanstalk/bin/get-config environment | jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' > /etc/profile.d/sh.local
packages:
    yum:
        jq: []

Note: The configuration file in step 1 is called setvars.config.

  1. Save the .ebextension file, and then deploy it to your Elastic Beanstalk environment.

  2. To test if the variables are being exported, connect to your instance using SSH, and then run the following command. Before testing, close any existing sessions and then reconnect using SSH. env | grep VARIABLE_NAME Important: For step 3, set VARIABLE_NAME to a variable defined in your environment.

The output shows if your environment variables are set correctly. In the following example output, a variable called RDS_PORT is defined in the Elastic Beanstalk environment.

$ env|grep RDS_PORT
RDS_PORT=3306

Note: Because you're using the commands on the .ebextension, you can update the sh.local file only with a new deployment. If you add or change a variable in the environment, then you must create a new deployment before the variable is exported to the operating system.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!