Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dengan template Dataflow, Anda dapat mengemas pipeline Dataflow untuk deployment.
Siapa pun yang memiliki izin yang benar kemudian dapat menggunakan template untuk men-deploy pipeline yang dikemas.
Anda dapat membuat template Dataflow kustom sendiri, dan Google menyediakan
template bawaan untuk skenario umum.
Manfaat
Template memiliki beberapa keunggulan dibandingkan dengan men-deploy pipeline secara langsung ke Dataflow:
Template memisahkan desain pipeline dari deployment. Misalnya, developer dapat membuat
template, dan ilmuwan data dapat men-deploy template tersebut di lain waktu.
Template dapat memiliki parameter yang memungkinkan Anda menyesuaikan pipeline saat men-deploy
template.
Anda dapat men-deploy template menggunakan konsol Google Cloud , Google Cloud CLI, atau panggilan REST API. Anda tidak memerlukan lingkungan pengembangan atau dependensi pipeline apa pun yang diinstal di
mesin lokal Anda.
Template adalah artefak kode yang dapat disimpan di repositori kontrol sumber dan digunakan dalam
pipeline continuous integration (CI/CD).
Template yang disediakan Google
Google menyediakan berbagai template Dataflow open source bawaan yang dapat Anda gunakan untuk skenario umum. Untuk mengetahui informasi selengkapnya tentang template yang tersedia, lihat
Template yang disediakan Google.
Membandingkan template Flex dan template klasik
Dataflow mendukung dua jenis template: Template Flex, yang lebih baru, dan
template klasik. Jika Anda membuat template Dataflow baru, sebaiknya
buat template tersebut sebagai template Flex.
Dengan template Flex, pipeline dikemas sebagai image Docker di
Artifact Registry, bersama dengan file spesifikasi template di Cloud Storage. Spesifikasi
template berisi pointer ke image Docker. Saat Anda menjalankan template, layanan Dataflow akan memulai VM peluncur, menarik image Docker, dan menjalankan pipeline. Grafik eksekusi dibuat secara dinamis berdasarkan parameter runtime yang diberikan oleh
pengguna. Untuk menggunakan API guna meluncurkan tugas yang menggunakan template Flex, gunakan
metode projects.locations.flexTemplates.launch.
Template klasik berisi serialisasi JSON dari grafik tugas Dataflow. Kode
untuk pipeline harus membungkus parameter runtime apa pun dalam antarmuka ValueProvider. Antarmuka ini memungkinkan pengguna menentukan nilai parameter saat men-deploy
template. Untuk menggunakan API guna bekerja dengan template klasik, lihat
dokumentasi referensi API
projects.locations.templates.
Template fleksibel memiliki keunggulan berikut dibandingkan template klasik:
Tidak seperti template klasik, template Flex tidak memerlukan antarmuka ValueProvider
untuk parameter input. Tidak semua sumber dan sink Dataflow mendukung
ValueProvider.
Meskipun template klasik memiliki grafik tugas statis, template Flex dapat membuat grafik tugas secara dinamis. Misalnya, template dapat memilih konektor I/O yang berbeda berdasarkan parameter
input.
Template Flex dapat melakukan praproses pada virtual machine (VM) selama konstruksi pipeline. Misalnya, fungsi ini dapat memvalidasi nilai parameter input.
Alur kerja template
Penggunaan template Dataflow mencakup langkah-langkah tingkat tinggi berikut:
Developer menyiapkan lingkungan pengembangan dan mengembangkan pipeline mereka. Lingkungan
mencakup Apache Beam SDK dan dependensi lainnya.
Bergantung pada jenis template (Flex atau klasik):
Untuk template Flex, developer mengemas pipeline ke dalam image Docker, mengirim
image ke Artifact Registry, dan mengupload file spesifikasi template
ke Cloud Storage.
Untuk template klasik, developer menjalankan pipeline, membuat file template, dan melakukan staging
template ke Cloud Storage.
Pengguna lain mengirimkan permintaan ke layanan Dataflow untuk menjalankan template.
Dataflow membuat pipeline dari template. Pipeline dapat memerlukan waktu
hingga lima hingga tujuh menit untuk mulai berjalan.
Menetapkan izin IAM
Tugas Dataflow, termasuk tugas yang dijalankan dari template, menggunakan dua akun layanan IAM:
Layanan Dataflow menggunakan
akun layanan Dataflow
untuk memanipulasi resource Google Cloud , seperti membuat VM.
VM worker Dataflow menggunakan
akun layanan worker
untuk mengakses file dan resource lain pipeline Anda. Akun layanan ini memerlukan akses ke resource apa pun yang dirujuk oleh tugas pipeline, termasuk sumber dan sink yang digunakan template. Untuk mengetahui informasi selengkapnya, lihat
Mengakses Google Cloud resource.
Pastikan kedua akun layanan ini memiliki peran yang sesuai. Untuk mengetahui informasi selengkapnya, lihat Keamanan dan izin Dataflow.
Persyaratan versi Apache Beam SDK
Untuk membuat template Anda sendiri, pastikan versi Apache Beam SDK Anda mendukung pembuatan template.
Java
Untuk membuat template dengan Apache Beam SDK 2.x untuk Java, Anda harus memiliki versi
2.0.0-beta3 atau yang lebih tinggi.
Python
Untuk membuat template dengan Apache Beam SDK 2.x untuk Python, Anda harus memiliki versi 2.0.0
atau yang lebih tinggi.
Untuk menjalankan template dengan Google Cloud CLI, Anda harus memiliki Google Cloud CLI versi 138.0.0 atau yang lebih tinggi.
Memperluas template
Anda dapat membuat template sendiri dengan memperluas template Dataflow
open source. Misalnya, untuk template yang menggunakan durasi periode tetap, data yang tiba di luar periode tersebut dapat dihapus. Untuk menghindari perilaku ini, gunakan kode template sebagai dasar, dan ubah kode untuk memanggil operasi .withAllowedLateness.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)"]]