如何将文件从 DAG 写入我的作曲家云存储桶?

How can I write a file from a DAG to my composer cloud storage bucket?

这个问题的指出

"...gs://my-bucket/dags 文件夹在 /home/airflow/gcs/dags 的调度程序、Web 服务器和工作程序中可用。"

(which is supported by the newer docs)

所以我写了一个这样的 bash 运算符:

t1 = bash.BashOperator(
    task_id='my_test',
    bash_command="touch /home/airflow/gcs/data/test.txt",
    )

我想通过在我的文件创建前加上答案中指定的路径,它将写入我的云作曲家环境的关联存储帐户中的数据文件夹。类似地,touch test.txt 也 运行 成功但实际上并没有在我能看到的任何地方创建文件(我假设它被写入工作人员的临时存储,然后在执行以下工作人员关闭时删除DAG)。我似乎无法通过 DAG 保留来自简单命令 运行 的任何数据?甚至可以简单地从 Cloud Composer 中的 bash 脚本 运行ning 写出一些文件吗?提前谢谢你。

奇怪的是,我需要在包含 Bash 命令的字符串末尾添加一个 space。

t1 = bash.BashOperator(
    task_id='my_test',
    bash_command="touch /home/airflow/gcs/data/test.txt ",
    )

令人沮丧的是错误说路径不存在,所以我进入了一个兔子洞,映射了 Airflow worker 的目录,直到我完全确定它存在 - 然后我发现了一个类似的问题 . Although I didn't get the 'Jinja Template not Found Error' I should have got according to this note.