[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-18 (世界標準時間)。"],[[["\u003cp\u003eDataflow templates allow you to package a Dataflow pipeline for deployment, enabling users with permissions to deploy the packaged pipeline.\u003c/p\u003e\n"],["\u003cp\u003eFlex templates are recommended over classic templates for new Dataflow template creation due to their advantages, such as not requiring the \u003ccode\u003eValueProvider\u003c/code\u003e interface and allowing for dynamic job graph construction.\u003c/p\u003e\n"],["\u003cp\u003eDataflow templates separate pipeline design from deployment, allowing customization through parameters and offering deployment via the Google Cloud console, CLI, or REST API without a development environment.\u003c/p\u003e\n"],["\u003cp\u003eUsing Dataflow templates involves developers packaging the pipeline and other users submitting a request to run it, with Dataflow then creating a pipeline from the template, which can take several minutes to start.\u003c/p\u003e\n"],["\u003cp\u003eDataflow jobs run from templates use two IAM service accounts, a Dataflow service account for manipulating resources and a worker service account for accessing pipeline files and resources.\u003c/p\u003e\n"]]],[],null,["Dataflow templates allow you to package a Dataflow pipeline for deployment.\nAnyone with the correct permissions can then use the template to deploy the packaged pipeline.\nYou can create your own custom Dataflow templates, and Google provides\n[pre-built templates](/dataflow/docs/templates/provided-templates) for common\nscenarios.\n\nBenefits\n\nTemplates have several advantages over directly deploying a pipeline to Dataflow:\n\n- Templates separate pipeline design from deployment. For example, a developer can create a template, and a data scientist can deploy the template at a later time.\n- Templates can have parameters that let you customize the pipeline when you deploy the template.\n- You can deploy a template by using the Google Cloud console, the Google Cloud CLI, or REST API calls. You don't need a development environment or any pipeline dependencies installed on your local machine.\n- A template is a code artifact that can be stored in a source control repository and used in continuous integration (CI/CD) pipelines.\n\nGoogle-provided templates\n\nGoogle provides a variety of pre-built, open source Dataflow templates that you\ncan use for common scenarios. For more information about the available templates, see\n[Google-provided templates](/dataflow/docs/templates/provided-templates).\n\nCompare Flex templates and classic templates\n\nDataflow supports two types of template: Flex templates, which are newer, and\nclassic templates. If you are creating a new Dataflow template, we recommend\ncreating it as a Flex template.\n\nWith a Flex template, the pipeline is packaged as a Docker image in\nArtifact Registry, along with a template specification file in Cloud Storage. The template\nspecification contains a pointer to the Docker image. When you run the template, the\nDataflow service starts a launcher VM, pulls the Docker image, and runs the\npipeline. The execution graph is dynamically built based on runtime parameters provided by the\nuser. To use the API to launch a job that uses a Flex template, use the\n[`projects.locations.flexTemplates.launch`](/dataflow/docs/reference/rest/v1b3/projects.locations.flexTemplates/launch) method.\n\nA classic template contains the JSON serialization of a Dataflow job graph. The\ncode for the pipeline must wrap any runtime parameters in the `ValueProvider`\ninterface. This interface allows users to specify parameter values when they deploy the\ntemplate. To use the API to work with classic templates, see the\n[`projects.locations.templates`](/dataflow/docs/reference/rest/v1b3/projects.locations.templates)\nAPI reference documentation.\n\nFlex templates have the following advantages over classic templates:\n\n- Unlike classic templates, Flex templates don't require the `ValueProvider` interface for input parameters. Not all Dataflow sources and sinks support `ValueProvider`.\n- While classic templates have a static job graph, Flex templates can dynamically construct the job graph. For example, the template might select a different I/O connector based on input parameters.\n- A Flex template can perform preprocessing on a virtual machine (VM) during pipeline construction. For example, it might validate input parameter values.\n\nTemplate workflow\n\nUsing Dataflow templates involves the following high-level steps:\n\n1. Developers set up a development environment and develop their pipeline. The environment includes the Apache Beam SDK and other dependencies.\n2. Depending on the template type (Flex or classic):\n - For Flex templates, the developers package the pipeline into a Docker image, push the image to Artifact Registry, and upload a template specification file to Cloud Storage.\n - For classic templates, developers run the pipeline, create a template file, and stage the template to Cloud Storage.\n3. Other users submit a request to the Dataflow service to run the template.\n4. Dataflow creates a pipeline from the template. The pipeline can take as much as five to seven minutes to start running.\n\nSet IAM permissions\n\nDataflow jobs, including jobs run from templates, use two IAM service accounts:\n\n- The Dataflow service uses a [Dataflow service account](/dataflow/docs/concepts/security-and-permissions#service_account) to manipulate Google Cloud resources, such as creating VMs.\n- The Dataflow worker VMs use a [worker service account](/dataflow/docs/concepts/security-and-permissions#worker-service-account) to access your pipeline's files and other resources. This service account needs access to any resources that the pipeline job references, including the source and sink that the template uses. For more information, see [Access Google Cloud resources](/dataflow/docs/concepts/security-and-permissions#access-resources).\n\nEnsure that these two service accounts have appropriate roles. For more\ninformation, see\n[Dataflow security and permissions](/dataflow/docs/concepts/security-and-permissions).\n\nApache Beam SDK version requirements\n\nTo create your own templates, make sure your Apache Beam SDK version supports template\ncreation. \n\nJava\n\nTo create templates with the Apache Beam SDK 2.x for Java, you must have version\n2.0.0-beta3 or higher.\n\nPython\n\nTo create templates with the Apache Beam SDK 2.x for Python, you must have version 2.0.0\nor higher.\n\nTo run templates with Google Cloud CLI, you must have [Google Cloud CLI](/sdk/downloads)\nversion 138.0.0 or higher.\n\nExtend templates\n\nYou can build your own templates by extending the\n[open source](https://github.com/GoogleCloudPlatform/DataflowTemplates)\nDataflow templates. For example, for a template that uses a fixed window duration, data\nthat arrives outside of the window might be discarded. To avoid this behavior, use the template\ncode as a base, and modify the code to invoke the\n[`.withAllowedLateness`](https://beam.apache.org/documentation/programming-guide/#managing-late-data) operation.\n\nWhat's next\n\n- [Google-provided templates](/dataflow/docs/templates/provided-templates)\n- [Creating classic templates](/dataflow/docs/templates/creating-templates)\n- [Running classic templates](/dataflow/docs/templates/executing-templates)\n- [Build and run Flex Templates](/dataflow/docs/guides/templates/using-flex-templates)\n- [Troubleshoot Flex Templates](/dataflow/docs/guides/troubleshoot-templates)"]]