2
votes

I am using Amazon Web Services (AWS) Elastic Beanstalk for hosting my Django/Python web application. I have two environments created in Beanstalk - production and acceptance (staging). My web app source code is in version control in git. Deployment config files are located in the .ebextensions directory at the root of git repository, as described here.

I have 2 separate Django config files for my application: conf/acceptance.py and conf/production.py.

How do I set DJANGO_SETTINGS_CONFIG environment variable separately for each environment?

I have tried editing it in beanstalk web ui, but it is resets when I redeploy. What can I do?

2

2 Answers

1
votes

I have exactly the same setup for one of my own apps. I'm using the Configuration > Software Configuration > Environment Properties section on the Beanstalk UI to set DJANGO_SETTINGS_MODULE as app.settings.production or app.settings.staging depending on the environment. This would likely be app.conf.production and app.conf.acceptance for you.

Could it be that one of your .ebxtensions files has an options_setting variable that is overriding this during deploy?

1
votes

To set a different value for each environment, you would need to create 2 env config files files for each environment in you .ebextensions folder, then pick ONLY the right one depending on where you deploy. This way your environment property DJANGO_SETTINGS_CONFIG would automatically be set during deployment and you won't need to change it in the web ui anymore.

Example:

Deploy this in acceptance environment:

env-config-acceptance.config

option_settings:
    - option_name: DJANGO_SETTINGS_CONFIG
      value: config.value.acceptance

Deploy this in production environment:

env-config-production.config

option_settings:
    - option_name: DJANGO_SETTINGS_CONFIG
      value: config.value.production