I have a Flask app that I have deployed to AWS Elastic Beanstalk and all works well. However I currently have the SQLAlchemy connection string hard-coded as the live AWS string. I need now to set thing up so that the AWS server automatically picks up the correct string, and my local environment uses the dev (local string). I have been reading the following post on how to achieve this:
Flask: How to manage different environment databases?
This makes sense in theory but I can't find any practical examples of how to actually achieve this on AWS Elastic Beanstalk. My init.py code looks like this:
from flask import Flask
from flask_debugtoolbar import DebugToolbarExtension
from flask_cors import CORS, cross_origin
from flask_sqlalchemy import SQLAlchemy
application = app = Flask(__name__)
app.config.from_object('config')
app.config.from_envvar('XXXXXPRODUCTION_CONFIG',silent=True)
db = SQLAlchemy(app)
CORS(app)
Config.py looks like this:
SQLALCHEMY_DATABASE_URI = 'mysql://root:xxxxxxx@localhost/xxxxx'
SQLALCHEMY_TRACK_MODIFICATIONS = False
DEBUG = True
And Config_production_dev.py looks like this:
SQLALCHEMY_DATABASE_URI = 'mysql://xxxxxx:xxxxxx@#########.cuhrbowyd8hk.eu-west-2.rds.amazonaws.com/ebdb'
SQLALCHEMY_TRACK_MODIFICATIONS = False
DEBUG = False
So everything is set up but I now have no idea how to initiate this part for the AWS instance:
app.config.from_envvar('XXXXXPRODUCTION_CONFIG',silent=True)
According to the post mentioned above I need something like this:
environment=XXXXXPRODUCTION_CONFIG="/home/tigra/mycoolapp/settings_production.py"
But is the path shown a path on my local machine? Or a path to my Elastic Beanstalk app? And if so how do I find the details of this path? Also how do I load this command up into the EB environment so that it executes? I can't find this information anywhere. Any help would be much appreciated.
I'm deploying the app using eb deploy in eb cli.