Skip to content

Environment Variables for Feature Flags and Flask Debugging

Latest
Compare
Choose a tag to compare
@evandbrown evandbrown released this 12 Jul 14:46
· 5 commits to master since this release

This release illustrates the use of environment variables to control feature flags and Flask debugging, leveraging Elastic Beanstalk configuration files to set the env vars on the application servers.

Use the New Features

Modify your application's Software Configuration (see Changing Software Configuration for detailed instructions) to first disable FLASK_DEBUG. Then, enable the cool new feature via a feature-flag by setting ENABLE_COOL_NEW_FEATURE to true.

About the New Features

We modify .ebextensions/python.config (from the previous release) and specify 3 new environment variables: FLASK_DEBUG, APP_VERSION, and ENABLE_COOL_NEW_FEATURE:

option_settings:
  - namespace: aws:elasticbeanstalk:container:python:staticfiles
    option_name: /static/
    value: static/
  - option_name: FLASK_DEBUG
    value: true
  - option_name: APP_VERSION
    value: v1.2.0
  - option_name: ENABLE_COOL_NEW_FEATURE
    value: false

Elastic Beanstalk makes these variables available to our application via the environment. We can access them in our app and, for example, decide if a new feature should be visible or not (i.e., a feature flag!):

# Get cool new feature flag from env
enable_cool_new_feature = os.environ.get('ENABLE_COOL_NEW_FEATURE') in ['true', 'True']

The ZIP file attached to this release can be deployed directly to AWS Elastic Beanstalk.