To set environment variables for an App Engine application, you need to define them in the app.yaml
configuration file. The process is slightly different for the Standard and Flexible environments.
- App Engine Standard Environment:
For the Standard Environment, define environment variables in the app.yaml
file under the env_variables
section. Here’s an example:
runtime: python39
instance_class: F1
env_variables:
API_KEY: 'your_api_key'
SECRET_KEY: 'your_secret_key'
ANOTHER_VAR: 'another_value'
handlers:
- url: /.*
script: auto
Replace your_api_key
, your_secret_key
, and another_value
with the appropriate values for your application.
- App Engine Flexible Environment:
For the Flexible Environment, define environment variables in the app.yaml
file under the env_variables
section in the runtime_config
. Here’s an example:
runtime: python
env: flex
runtime_config:
python_version: 3
env_variables:
API_KEY: 'your_api_key'
SECRET_KEY: 'your_secret_key'
ANOTHER_VAR: 'another_value'
entrypoint: gunicorn -b :$PORT main:app
Replace your_api_key
, your_secret_key
, and another_value
with the appropriate values for your application.
After defining the environment variables in the app.yaml
file, deploy your App Engine application using the gcloud app deploy
command. The environment variables will be available to your application code during runtime.
Leave a Reply