python - 在用 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 中找不到...
有任何想法吗 ?
解决方案
这--service_account_email
是这里提到的推荐方法。不建议下载密钥并将其存储在本地或 GCE 上。
推荐阅读
- docker - Docker构建:返回一个非零代码:1,当测试失败时
- python - 将 2 个 python GUI 菜单合并在一起
- javascript - 循环一个 Promise
- java - InputConnection.sendKeyEvent 不起作用
- matplotlib - 无法使用 MatPlotLib 获得等于绘图的数组维度
- javascript - Vue路由不正确渲染
- docker - 连接期间本地gitlab管道错误
- javascript - Mapbox JS SDK CSS 样式表导致地图消失
- c# - 如何使用 C# 连接到 Google Cloud SQL Server?
- python - Selenium 切换到框架