【问题标题】:How to extract REST API parameters from DataFlow template?如何从 DataFlow 模板中提取 REST API 参数?
【发布时间】:2020-12-08 10:10:02
【问题描述】:

我想在 Google Cloud Platform 中使用 Cloud Function 触发数据流。

在 Cloud Function 中,我使用 Python 像这样调用 API

from googleapiclient.discovery import build

service = build('dataflow', 'v1b3', cache_discovery=False)

request = service.projects().locations().templates().launch(
    projectId=projectId, gcsPath=srcDataFlowTemplate, location='us', body={
        'jobName': jobName,
        'parameters': parameters,
        'environment':environment
    }
)

response = request.execute()

这是我正在启动的数据流模板中的管道:

(p
   | 'Create PCollection' >> beam.Create(inputFile)
   | 'Read from a File' >> beam.io.ReadAllFromText(skip_header_lines=1)
   | 'Write to BigQuery' >> beam.io.Write(beam.io.WriteToBigQuery (table,
                project=projectId,
                dataset=dataset,
                schema=schema,
                create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED,
                write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND
        )
    )
)

在数据流模板中 - 是否可以从 API 调用中提取存储在请求正文中的参数属性和 projectId 下的这个“inputFile”?

【问题讨论】:

  • 你能列出你想要的变量吗?为什么?我可以很容易地得到一些,其他的更难,我想在深入研究之前确定!
  • 我已经更新了我的问题。我是这个环境的新手,所以我不知道这是否可能。我基本上想在拨打此电话后在 DataFlow 模板中提取此 {projectId}:https://dataflow.googleapis.com/v1b3/projects/{projectId}/templates:launch

标签: google-cloud-platform apache-beam google-apis-explorer


【解决方案1】:

当您使用 Beam 框架在 Dataflow 上运行作业时,您会使用 DataflowRunner。创建管道时,您使用“选项”对象创建它。

p = beam.Pipeline(options=options)

This object contains basic parameters,比如projectId,可以扩展添加自己的管道参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多