Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Mit Dataflow-Vorlagen können Sie eine Dataflow-Pipeline für die Bereitstellung verpacken.
Jeder Nutzer mit den entsprechenden Berechtigungen kann dann die Vorlage zum Bereitstellen der Paket-Pipeline verwenden.
Sie können eigene benutzerdefinierte Dataflow-Vorlagen erstellen. Google bietet vordefinierte Vorlagen für gängige Szenarien.
Vorteile
Vorlagen bieten mehrere Vorteile gegenüber der direkten Bereitstellung einer Pipeline in Dataflow:
Vorlagen trennen das Pipelinedesign von der Bereitstellung. Beispielsweise kann ein Entwickler eine Vorlage erstellen und ein Data Scientist kann diese zu einem späteren Zeitpunkt bereitstellen.
Vorlagen können Parameter enthalten, mit denen Sie die Pipeline bei der Bereitstellung der Vorlage anpassen können.
Sie können eine Vorlage mithilfe der Google Cloud Console, der Google Cloud CLI oder der REST API-Aufrufe bereitstellen. Sie benötigen keine Entwicklungsumgebung oder Pipeline-Abhängigkeiten, die auf Ihrem lokalen Computer installiert sind.
Eine Vorlage ist ein Codeartefakt, das in einem Versionsverwaltungs-Repository gespeichert und in Continuous Integration-Pipelines (CI/CD) verwendet werden kann.
Von Google bereitgestellte Vorlagen
Google bietet eine Vielzahl vordefinierter Open-Source-Dataflow-Vorlagen, die Sie für gängige Szenarien verwenden können. Weitere Informationen zu den verfügbaren Vorlagen finden Sie unter Von Google bereitgestellte Vorlagen.
Flexible Vorlagen mit klassischen Vorlagen vergleichen
Dataflow unterstützt zwei Arten von Vorlagen: Flex-Vorlagen, neuere und klassische Vorlagen. Wenn Sie eine neue Dataflow-Vorlage erstellen, empfehlen wir, sie als Flex-Vorlage zu erstellen.
Mit einer Flex-Vorlage wird die Pipeline zusammen mit einer Vorlagenspezifikationsdatei in Cloud Storage als Docker-Image in Artifact Registry gepackt. Die Vorlagenspezifikation enthält einen Verweis auf das Docker-Image. Wenn Sie die Vorlage ausführen, startet der Dataflow-Dienst eine Launcher-VM, ruft das Docker-Image ab und führt die Pipeline aus. Die Ausführungsgrafik wird auf Basis der vom Nutzer bereitgestellten Laufzeitparameter dynamisch erstellt. Verwenden Sie die projects.locations.flexTemplates.launch-Methode, um mit der API einen Job zu starten, der eine Flex-Vorlage nutzt.
Eine klassische Vorlage enthält die JSON-Serialisierung einer Dataflow-Jobgrafik. Der Code für die Pipeline muss alle Laufzeitparameter in die Schnittstelle ValueProvider einschließen. Über diese Schnittstelle können Nutzer beim Bereitstellen der Vorlage Parameterwerte angeben. Informationen zur Verwendung der API für klassische Vorlagen finden Sie in der API-Referenzdokumentation zu projects.locations.templates.
Flex-Vorlagen haben die folgenden Vorteile gegenüber herkömmlichen Vorlagen:
Im Gegensatz zu klassischen Vorlagen benötigen Flex-Vorlagen die Schnittstelle ValueProvider für Eingabeparameter nicht. Nicht alle Dataflow-Quellen und -Senken unterstützen ValueProvider.
Während klassische Vorlagen eine statische Jobgrafik haben, können Flex-Vorlagen die Jobgrafik dynamisch erstellen. Die Vorlage kann beispielsweise einen anderen E/A-Connector anhand der Eingabeparameter auswählen.
Eine Flex-Vorlage kann die Vorverarbeitung auf einer virtuellen Maschine (VM) während der Pipelineerstellung durchführen. So können zum Beispiel Eingabeparameterwerte validiert werden.
Vorlagen-Workflow
Die Verwendung von Dataflow-Vorlagen umfasst die folgenden allgemeinen Schritte:
Entwickler richten eine Entwicklungsumgebung ein und entwickeln ihre Pipeline. Die Umgebung enthält das Apache Beam-SDK und andere Abhängigkeiten.
Je nach Vorlagentyp (Flex oder Classic):
Bei Flex-Vorlagen packen die Entwickler die Pipeline in ein Docker-Image, übertragen das Image in Artifact Registry und laden eine Vorlagenspezifikationsdatei in Cloud Storage hoch.
Bei klassischen Vorlagen führen Entwickler die Pipeline aus, erstellen eine Vorlagendatei und stellen die Vorlage in Cloud Storage bereit.
Andere Nutzer senden eine Anfrage an den Dataflow-Dienst, um die Vorlage auszuführen.
Dataflow erstellt eine Pipeline aus der Vorlage. Es kann bis zu fünf bis sieben Minuten dauern, bis die Pipeline ausgeführt wird.
IAM-Berechtigungen festlegen
Dataflow-Jobs, einschließlich Jobs, die über Vorlagen ausgeführt werden, verwenden zwei IAM-Dienstkonten:
Der Dataflow-Dienst verwendet ein Dataflow-Dienstkonto, um Google Cloud Ressourcen wie VMs zu bearbeiten.
Die Dataflow-Worker-VMs verwenden ein Worker-Dienstkonto, um auf die Dateien und andere Ressourcen Ihrer Pipeline zuzugreifen. Dieses Dienstkonto benötigt Zugriff auf alle Ressourcen, auf die der Pipelinejob verweist, einschließlich der von der Vorlage verwendeten Quellen und Senken. Weitere Informationen finden Sie unter Auf Google Cloud Ressourcen zugreifen.
Überprüfen Sie, ob Ihre Apache Beam-SDK-Version die Vorlagenerstellung für eigene Vorlagen unterstützt.
Java
Zum Erstellen von Vorlagen mit dem Apache Beam SDK 2.x für Java benötigen Sie die Version 2.0.0-beta3 oder höher.
Python
Zum Erstellen von Vorlagen mit dem Apache Beam SDK 2.x für Python benötigen Sie die Version 2.0.0 oder höher.
Zum Ausführen von Vorlagen mit der Google Cloud-Befehlszeile benötigen Sie Google Cloud CLI Version 138.0.0 oder höher.
Vorlagen erweitern
Sie können eigene Vorlagen erstellen, indem Sie die Open-Source-Vorlagen von Dataflow erweitern. Bei einer Vorlage, die eine feste Fensterdauer verwendet, können beispielsweise Daten, die außerhalb des Fensters eingehen, verworfen werden. Verwenden Sie den Vorlagencode als Basis und ändern Sie den Code zum Aufrufen des Vorgangs .withAllowedLateness, um dieses Verhalten zu vermeiden.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-18 (UTC)."],[[["\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--------\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-------------------------\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--------------------------------------------\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-----------------\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-------------------\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------------------------------------\n\nTo create your own templates, make sure your Apache Beam SDK version supports template\ncreation. \n\n### Java\n\nTo create templates with the Apache Beam SDK 2.x for Java, you must have version\n2.0.0-beta3 or higher.\n\n### Python\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----------------\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\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)"]]