Use YAML files with workflows Stay organized with collections Save and categorize content based on your preferences.
You can define a workflow template in a YAML file, then instantiate the templateto run the workflow. You can also import and export a workflow template YAMLfile to create and update a Dataproc workflow template resource.
Also seeUsing inline Dataproc workflows for other ways to run a workflow without creating a workflowtemplate resource.Run a workflow using a YAML file
To run a workflow without first creating a workflow template resource,use thegcloud dataproc workflow-templates instantiate-from-filecommand.
- Define your workflow template in a YAML file. The YAML file must include allrequiredWorkflowTemplatefields except the
idfield, and it must also excludetheversionfield and all output-only fields.In the following workflow example, theprerequisiteStepIdslist intheterasortstep ensures theterasortstep will only begin after theteragenstep completessuccessfully.jobs:- hadoopJob: args: - teragen - '1000' - hdfs:///gen/ mainJarFileUri: file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar stepId: teragen- hadoopJob: args: - terasort - hdfs:///gen/ - hdfs:///sort/ mainJarFileUri: file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar stepId: terasort prerequisiteStepIds: - teragenplacement: managedCluster: clusterName: my-managed-cluster config: gceClusterConfig: zoneUri: us-central1-a
- Run the workflow:
gcloud dataproc workflow-templates instantiate-from-file \ --file=TEMPLATE_YAML \ --region=REGION
Instantiate a workflow using a YAML file with Dataproc Auto Zone Placement
- Define your workflow template in a YAML file. This YAML file is the same as the previous YAML file, except the
zoneUrifield is set to the empty string ('') to allow DataprocAuto Zone Placement to select the zone for the cluster.jobs:- hadoopJob: args: - teragen - '1000' - hdfs:///gen/ mainJarFileUri: file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar stepId: teragen- hadoopJob: args: - terasort - hdfs:///gen/ - hdfs:///sort/ mainJarFileUri: file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar stepId: terasort prerequisiteStepIds: - teragenplacement: managedCluster: clusterName: my-managed-cluster config: gceClusterConfig: zoneUri: ''
- Run the workflow. When using Auto Placement, you must pass aregion to the
gcloudcommand.gcloud dataproc workflow-templates instantiate-from-file \ --file=TEMPLATE_YAML \ --region=REGION
Import and export a workflow template YAML file
You can import and export workflow template YAML files. Typically, a workflowtemplate is first exported as a YAML file, then the YAML is edited, and thenthe edited YAML file is imported to update the template.
Export the workflow templateto a YAML file. During the export operation,the
idandversionfields, and all output-only fieldsare filtered from the output and do not appear in theexported YAML file. You can pass either theWorkflowTemplategcloud dataproc workflow-templates exportTEMPLATE_ID or TEMPLATE_NAME \ --destination=TEMPLATE_YAML \ --region=REGION
idor the fully qualified template resourcename("projects/PROJECT_ID/regions/REGION/workflowTemplates/TEMPLATE_ID") to the command.If you omit the--destinationflag,the output is directed tostdout, so the following commandwill also export the template to a YAML file:gcloud dataproc workflow-templates exportTEMPLATE_ID or TEMPLATE_NAME \ --region=REGION >TEMPLATE_YAML
Edit the YAML file locally. Note that the
id,version,and output-only fields, which were filteredfrom the YAML file when the template was exported, are disallowed in theimported YAML file.Import the updated workflow templateYAML file:
You can pass either theWorkflowTemplategcloud dataproc workflow-templates importTEMPLATE_ID or TEMPLATE_NAME \ --source=TEMPLATE_YAML \ --region=REGION
idor the fully qualified template resourcename("projects/PROJECT_ID/regions/region/workflowTemplates/TEMPLATE_ID") to the command. The template resource with the same template name will be overwritten (updated)and its version number will be incremented. If a template with the same templatename does not exist, it will be created.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.