首页 > 解决方案 > 在用 python 编码的 Apache-Beam 管道中提供 BigQuery 凭据

问题描述

我正在尝试使用云数据流运行器从我的光束管道中的 bigquery 读取数据。我想提供访问该项目的凭据。

我在 Java 中看到过示例,但在 Python 中没有看到过。

我发现的唯一可能性是使用:-- service_account_email参数但是如果我想在代码本身的所有选项中提供 .json 密钥信息,例如:google_cloud_options.service_account = '/path/to/credential.json'

options = PipelineOptions(flags=argv)
google_cloud_options = options.view_as(GoogleCloudOptions)
google_cloud_options.project = 'project_name'
google_cloud_options.job_name = 'job_name'
google_cloud_options.staging_location = 'gs://bucket'
google_cloud_options.temp_location = 'gs://bucket'
options.view_as(StandardOptions).runner = 'DataflowRunner'

with beam.Pipeline(options=options) as pipeline:
    query = open('query.sql', 'r')
    bq_source = beam.io.BigQuerySource(query=query.read(), use_standard_sql=True)
    main_table = \
        pipeline \
        | 'ReadAccountViewAll' >> beam.io.Read(bq_source) \

Java 有一个方法getGcpCredential但在 Python 中找不到...

有任何想法吗 ?

标签: pythongoogle-cloud-dataflowapache-beam

解决方案


--service_account_email这里提到的推荐方法。不建议下载密钥并将其存储在本地或 GCE 上。


推荐阅读