Search code examples
amazon-web-servicessymfonyamazon-ec2environment-variablesamazon-elastic-beanstalk

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

Solution

  • 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)