Using PYTHON to run a Google Dataflow Template

后端 未结 1 1245
无人共我
无人共我 2021-01-07 08:37

I want to execute a Google Dataflow Template using PYTHON. Actually, I have been executing Dataflow Templates using the Dataflow REST API or the Cloud Fun

相关标签:
1条回答
  • 2021-01-07 09:39

    You can do that using the template launch method from the Dataflow API Client Library for Python like so:

    import googleapiclient.discovery
    from oauth2client.client import GoogleCredentials
    
    project = PROJECT_ID
    location = LOCATION
    
    credentials = GoogleCredentials.get_application_default()
    
    dataflow = googleapiclient.discovery.build('dataflow', 'v1b3', credentials=credentials)
    result = dataflow.projects().templates().launch(
            projectId=project,
            body={
              "environment": {
                "zone": "us-central1-f",
                "tempLocation": "gs://{{my-cloud-storage-bucket}}/tmp"
              },
              "parameters": {
                  "inputLocations" : "{\"location1\":\"gs://{{my-cloud-storage-bucket}}/my-folder/**/*\"}",
                  "outputLocations": "{\"location1\":\"gs://{{my-cloud-storage-bucket}}/my-output/output.csv\"}"
              },
              "jobName": SOME_NAME
            },
            gcsPath = PATH_TO_TEMPLATE
    ).execute()
    
    0 讨论(0)
提交回复
热议问题