Launching Dataflow template jobs on a specific region fails with “Workflow could not be created”

Problem

Using theprojects.templates/launch method to launch Dataflow template jobs on specific regions such as europe-west2, the job fails with error:
The workflow could not be created, since it was sent to an invalid regional endpoint (europe-west2). Please resubmit to a valid Cloud Dataflow regional endpoint. The list of Cloud Dataflow regional endpoints is at.

Environment

  • Cloud Dataflow
  • Templates

Solution

  1. Instead of using projects.templates/launch method, use regionalized templates for example, projects.locations.templates/launch method which takes location as a parameter and can be invoked as below:
    POST https://dataflow.googleapis.com/v1b3/projects/YOUR_PROJECT_ID/locations/LOCATION/templates:launch?gcsPath=gs://YOUR_BUCKET_NAME/templates/TemplateName
    {
          "jobName": "JOB_NAME",
          "parameters": {
                   "inputFile" : "gs://YOUR_BUCKET_NAME/input/my_input.txt",
                    "outputFile": "gs://YOUR_BUCKET_NAME/output/my_output"
           },
          "environment": {
                    "tempLocation": "gs://YOUR_BUCKET_NAME/temp",
                   "zone": "us-central1-f"
         }
    }
    

Cause

This occurs when using legacy API method projects.templates.launch that routes through the default region us-central1.