云函数触发数据流时,如何在数据流中传递requirements.txt参数?

2024-04-26 14:35:21 发布

您现在位置:Python中文网/ 问答频道 /正文

目标-我有一个数据流模板(用python编写)它依赖于pandas和nltk,我还想从云函数触发数据流作业。为此,我已经将代码上传到一个bucket中,并准备在cloud函数中指定模板位置

问题-当您使用discovery google module from cloud功能触发数据流作业时,如何传递通常用于安装任何第三方库的requirements\u file参数

先决条件-我知道,通过指定本地目录路径通过本地计算机启动作业时,可以实现这一点,但当我尝试从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.


Tags: 函数代码路径txtgs模板cloud目标
1条回答
网友
1楼 · 发布于 2024-04-26 14:35:21

数据流的模板不是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结构,该文件是您编写的数据流代码的编译版本,在编译过程中,它将从本地目录中读取requirements.txt,并编译其步骤。然后,您可以将模板添加到一个bucket中,并提供云函数的路径,您不必在创建模板后担心requirements.txt文件

相关问题 更多 >