App Engine allows developers to focus on doing what they do best, writing code. Based on Google Compute Engine, the App Engine flexible environment automatically scales your app up and down while balancing the load. Microservices, authorization, SQL and NoSQL databases, traffic splitting, logging, versioning, security scanning, and content delivery networks are all supported natively. In addition, the App Engine flexible environment allows you to customize the runtime and even the operating system of your virtual machine using Dockerfiles. You may find related information on the "App Engine Flexible Environment" documentation
page.
The "cloud_sql_instances: INSTANCE_CONNECTION_NAME" instruction from app.yaml is meant for this Flexible managed environment. It is difficult to view it as hard coding. In what concerns Django, this is your framework of choice, and you are in a position to take the most advantageous decisions. Instead of hard coding, you could, for instance, make use of the already set environment variables:
env_variables:
# Replace user, password, database, and instance connection name with the values obtained
# when configuring your Cloud SQL instance.
SQLALCHEMY_DATABASE_URI: >-
mysql+pymysql://USER:PASSWORD@/DATABASE?unix_socket=/cloudsql/INSTANCE_CONNECTION_NAME
#[END gae_flex_mysql_env]
This allows you to reference environment variables in your Python code. For an example, you could follow the example on the "Using Cloud SQL for MySQL" documentation
page.
# Environment variables are defined in app.yaml.
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['SQLALCHEMY_DATABASE_URI']
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
The above code excerpt illustrates how you may refer environment variables in your Python code.