Cloud Function 触发 Dataflow 时如何在 Dataflow 中传递 requirements.txt 参数?

How to pass requirements.txt parameter in Dataflow when Dataflow is being triggered by Cloud Function?

Objective- 我有一个数据流模板 (写在 python) 依赖于pandas 和 nltk 我也想从云功能触发数据流作业。为此,我已将代码上传到存储桶中,并准备在云函数中指定模板位置。

问题-如何传递 requirements_file 参数,当您使用发现 google 来自云功能的模块?

Prerequisites- 我知道这可以在您通过指定本地目录路径通过本地计算机启动作业时完成,但是当我尝试从 GCS 指定路径时作为 --requirements_file gs://bucket/requirements.txt 它给了我一个错误说:

The file gs://bucket/requirements.txt cannot be found. It was specified in the --requirements_file command line option.

dataflow 模板不是 python 或 java 代码,而是您在 python 或 java 中编写的代码的编译版本].因此,当您创建模板时,您可以像往常一样在参数中传递 requirements.txt,如下所示

python dataflow-using-cf.py \
    --runner DataflowRunner \
    --project <PROJECT_ID> \
    --staging_location gs://<BUCKET_NAME>/staging \
    --temp_location gs://<BUCKET_NAME>/temp \
    --template_location ./template1 \
    --requirements_file ./requirements.txt \

以上命令将创建一个名称为 template1 的文件,如果您阅读该文件,它包含一个 JSON 结构,该文件是您编写的 Dataflow 代码的编译版本编译过程,它会从你的本地目录读取你的 requirements.txt 并编译它的步骤。然后您可以将您的模板添加到存储桶并提供云函数的路径,您不必担心创建模板后的 requirements.txt 文件。