1
votes

What is the best practice for managing environment variable configuration files for git repositories with multiple environment branches that are deployed to different environments on Elastic Beanstalk using "eb deploy"?

I have a git repository with prod and dev branches, and EB set up with prod and dev environments, and an environment config file for each env (env.config for prod, and env_dev.config for dev). The env files are in .gitignore, but not in .ebignore, so they are not in source control, but are deployed to EB.

How can I set this up so that env.config is only deployed to production, and env_dev.config is only deployed to dev? I asked AWS support, and they said there is no way to have a conditional on the environment level that would tell it what config file to include.

Another idea was having an .ebignore file in each branch that ignored the env.config file of the other branch, but when I merged development branch to production, this file would come too.

1
Did you have any luck getting something to work? We're running into the same problem now.Eric T
What I ended up doing was not using an elastic beanstalk environment as a dev server, I just use a plain EC2 instance that I connect to on Atom using the Remote FTP package. I'm using Laravel, so my env variables are from .env that is just uploaded with the app to my EC2 instance.user339568

1 Answers

0
votes

You can achieve this using ebextensions's container_commands:

  1. source the ENVIRONMENT environment variable somehow.
  2. Create an .ebextension container command which basically will source the right file to get sourced. The .ebextension file, say env_sourcer.config, would look like follows:

    container_commands:
      if [ $ENVIRONMENT == 'PRODUCTION' ]; then source ./env.config; else source ./env_dev.config; fi