英文:
Create job from Dataflow template from Go app
问题
我正在尝试通过Go应用程序从现有模板启动一个Dataflow作业。
到目前为止,我已经引入了google.golang.org/api/dataflow/v1b3
包,并使用作业信息创建了一个CreateJobFromTemplateRequest
。
现在,我该如何使用Compute Engine中的内置服务帐号凭据执行该请求呢?
英文:
I'm trying to launch a Dataflow job from an existing template, via a Go app.
So far, I've brought in google.golang.org/api/dataflow/v1b3
and created a CreateJobFromTemplateRequest
with the job info.
How can I now execute that request using the built-in service account credentials in Compute Engine?
答案1
得分: 5
使用自动生成的Google Go API仅在为您要调用的服务开发了Google Go客户端库的情况下才推荐使用。目前还没有适用于Dataflow的客户端库。
要使用默认凭据从Go应用程序启动Dataflow模板:
ctx := context.Background()
oauthClient, err := google.DefaultClient(ctx, dataflow.CloudPlatformScope)
dataflowService, err := dataflow.New(oauthClient)
if err != nil {
panic(err)
}
templateRequest := dataflow.CreateJobFromTemplateRequest{
GcsPath: "在此处填写模板的GCS路径",
JobName: "在此处选择一个唯一的作业名称",
Parameters: map[string]string{
"parameters": "用于作业的参数",
},
}
result, err := dataflowService.Projects.Templates.Create("项目ID", &templateRequest).Do()
if err != nil {
panic(err)
}
英文:
Using Auto-generated Google APIs for Go is only recommended if there is a Google Client Library for Go developed for the service you are calling. There is not a client library yet for Dataflow.
To launch a Dataflow template from a Go app using default credentials:
ctx := context.Background()
oauthClient, err := google.DefaultClient(ctx, dataflow.CloudPlatformScope)
dataflowService, err := dataflow.New(oauthClient)
if err != nil {
panic(err)
}
templateRequest := dataflow.CreateJobFromTemplateRequest{
GcsPath: "gcs path to template here",
JobName: "choose a unique job name here",
Parameters: map[string]string{
"parameters": "for job",
},
}
result, err := dataflowService.Projects.Templates.Create("project id", &templateRequest).Do()
if err != nil {
panic(err)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论