Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
Las plantillas de Dataflow te permiten empaquetar un flujo de procesamiento de Dataflow para desplegarlo.
Cualquier persona que tenga los permisos correctos podrá usar la plantilla para implementar la canalización empaquetada.
Puedes crear tus propias plantillas de Dataflow personalizadas. Además, Google ofrece plantillas prediseñadas para situaciones habituales.
Ventajas
Las plantillas ofrecen varias ventajas con respecto al despliegue directo de un flujo de procesamiento en Dataflow:
Las plantillas separan el diseño del flujo de procesamiento de la implementación. Por ejemplo, un desarrollador puede crear una plantilla y un científico de datos puede implementarla más adelante.
Las plantillas pueden tener parámetros que te permitan personalizar la canalización cuando despliegues la plantilla.
Puedes desplegar una plantilla mediante la consola, la CLI de Google Cloud o llamadas a la API REST. Google Cloud No necesitas un entorno de desarrollo ni ninguna dependencia de canalización instalada en tu máquina local.
Una plantilla es un artefacto de código que se puede almacenar en un repositorio de control de versiones y usar en flujos de procesamiento de integración continua y entrega continua (CI/CD).
Plantillas proporcionadas por Google
Google ofrece varias plantillas de Dataflow predefinidas y de código abierto que puedes usar en situaciones habituales. Para obtener más información sobre las plantillas disponibles, consulta el artículo sobre las plantillas proporcionadas por Google.
Comparar plantillas Flex y plantillas clásicas
Dataflow admite dos tipos de plantillas: las flexibles, que son más recientes, y las clásicas. Si vas a crear una plantilla de Dataflow, te recomendamos que la crees como plantilla flex.
Con una plantilla flexible, la canalización se empaqueta como una imagen de Docker en Artifact Registry, junto con un archivo de especificación de plantilla en Cloud Storage. La especificación de la plantilla
contiene un puntero a la imagen de Docker. Cuando ejecutas la plantilla, el servicio Dataflow inicia una VM de inicio, extrae la imagen de Docker y ejecuta el flujo de procesamiento. El gráfico de ejecución se crea dinámicamente en función de los parámetros de tiempo de ejecución que proporcione el usuario. Para usar la API y lanzar un trabajo que utilice una plantilla Flex, usa el método projects.locations.flexTemplates.launch.
Una plantilla clásica contiene la serialización JSON de un gráfico de tareas de Dataflow. El código de la canalización debe envolver los parámetros de tiempo de ejecución en la interfaz ValueProvider. Esta interfaz permite a los usuarios especificar valores de parámetros cuando implementan la plantilla. Para usar la API y trabajar con plantillas clásicas, consulta la
projects.locations.templates
documentación de referencia de la API.
Las plantillas flexibles tienen las siguientes ventajas con respecto a las clásicas:
A diferencia de las plantillas clásicas, las plantillas flexibles no requieren la interfaz ValueProvider
para los parámetros de entrada. No todas las fuentes y receptores de Dataflow admiten ValueProvider.
Mientras que las plantillas clásicas tienen un gráfico de tareas estático, las plantillas Flex pueden crear el gráfico de tareas de forma dinámica. Por ejemplo, la plantilla puede seleccionar un conector de E/S diferente en función de los parámetros de entrada.
Una plantilla flexible puede realizar un preprocesamiento en una máquina virtual (VM) durante la construcción de la canalización. Por ejemplo, puede validar los valores de los parámetros de entrada.
Flujo de trabajo de plantilla
Para usar plantillas de Dataflow, debe seguir estos pasos generales:
Los desarrolladores configuran un entorno de desarrollo y desarrollan su canal. El entorno incluye el SDK de Apache Beam y otras dependencias.
En función del tipo de plantilla (Flex o clásica):
En el caso de las plantillas Flex, los desarrolladores empaquetan la canalización en una imagen Docker, transfieren la imagen a Artifact Registry y suben un archivo de especificación de plantilla a Cloud Storage.
En el caso de las plantillas clásicas, los desarrolladores ejecutan el flujo de procesamiento, crean un archivo de plantilla y almacenan la plantilla en Cloud Storage.
Otros usuarios envían una solicitud al servicio Dataflow para ejecutar la plantilla.
Dataflow crea un flujo de procesamiento a partir de la plantilla. La canalización puede tardar entre cinco y siete minutos en empezar a ejecutarse.
Establecer permisos de gestión de identidades y accesos
Los trabajos de Dataflow, incluidos los que se ejecutan a partir de plantillas, usan dos cuentas de servicio de IAM:
El servicio Dataflow usa una cuenta de servicio de Dataflow para manipular recursos de Google Cloud , como crear máquinas virtuales.
Las VMs de trabajador de Dataflow usan una cuenta de servicio de trabajador para acceder a los archivos y otros recursos de tu canalización. Esta cuenta de servicio necesita acceder a todos los recursos a los que haga referencia el trabajo de la canalización, incluidos el origen y el receptor que utilice la plantilla. Para obtener más información, consulta Acceder Google Cloud a recursos.
Para crear tus propias plantillas, asegúrate de que tu versión del SDK de Apache Beam admita la creación de plantillas.
Java
Para crear plantillas con el SDK de Apache Beam 2.x para Java, debes tener la versión 2.0.0-beta3 o una posterior.
Python
Para crear plantillas con el SDK de Apache Beam 2.x para Python, debes tener la versión 2.0.0 o una posterior.
Para ejecutar plantillas con Google Cloud CLI, debes tener la versión 138.0.0 o una posterior de Google Cloud CLI.
Ampliar plantillas
Puedes crear tus propias plantillas ampliando las plantillas de Dataflow de código abierto. Por ejemplo, en una plantilla que usa una duración de ventana fija, los datos que llegan fuera de la ventana se pueden descartar. Para evitar este comportamiento, utilice el código de la plantilla como base y modifíquelo para invocar la operación .withAllowedLateness.
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-10 (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\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)"]]