首页 > 解决方案 > 在 Google Cloud Composer 中使用 json 文件导入变量

问题描述

如何使用命令行将 json 文件导入 Google Cloud Composer?

我尝试了以下命令

gcloud composer environments run comp-env --location=us-central1 variables -- --import composer_variables.json

我收到以下错误

[2019-01-17 13:34:54,003] {configuration.py:389} INFO - Reading the config from /etc/airflow/airflow.cfg
[2019-01-17 13:34:54,117] {app.py:44} WARNING - Using default Composer Environment Variables. Overrides have not been applied.
Missing variables file.

但是,当我使用以下命令设置单个变量时,它工作正常。

gcloud composer environments run comp-env --location=us-central1 variables -- --set variable_name variable_value

由于我要导入的变量超过 75 个,因此我们需要使用 json 文件导入它。请帮我解决这个问题

标签: google-cloud-platformairflowgoogle-cloud-composer

解决方案


以下命令在 Airflow 容器内远程gcloud composer environments run {environment-name} variables -- --i {path-to-json-file}执行。airflow variables因此,需要在 Airflow worker/scheduler pod 中访问 json 文件。因此,您需要var.json先将您的复制到 GCS,然后运行该命令。例如:

  1. gcloud composer environments storage data import --source=your-var.json --environment={environment-name} --location={location}
  2. gcloud composer environments run {environment-name} --location={location} variables -- --i /home/airflow/gcs/data/your-var.json.

推荐阅读