Dataflow 템플릿을 사용하면 배포에 대해 Dataflow 파이프라인을 패키징할 수 있습니다.
올바른 권한이 있는 누구나 템플릿을 사용하여 패키징된 파이프라인을 배포할 수 있습니다.
자체 커스텀 Dataflow 템플릿을 만들 수 있고 Google에서는 일반적인 시나리오를 위해 사전 빌드된 템플릿이 제공됩니다.
이점
템플릿은 Dataflow에 직접 파이프라인을 배포하는 것에 비해 몇 가지 장점이 있습니다.
템플릿은 파이프라인 설계를 배포와 구분합니다. 예를 들어 개발자가 템플릿을 만들고, 데이터 과학자는 나중에 템플릿을 배포할 수 있습니다.
템플릿에는 템플릿을 배포할 때 파이프라인을 맞춤설정할 수 있게 해주는 매개변수가 포함될 수 있습니다.
Google Cloud 콘솔, Google Cloud CLI, REST API 호출을 사용하여 템플릿을 배포할 수 있습니다. 개발 환경 또는 파이프라인 종속 항목을 로컬 머신에 설치할 필요가 없습니다.
템플릿은 소스 제어 저장소에 저장하고 지속적 통합(CI/CD) 파이프라인에 사용할 수 있는 코드 아티팩트입니다.
Google 제공 템플릿
Google에서는 일반적인 시나리오에 사용할 수 있는 사전 빌드된 오픈소스 Dataflow 템플릿을 다양하게 제공합니다. 사용 가능한 템플릿에 대한 자세한 내용은 Google 제공 템플릿을 참조하세요.
Flex 템플릿과 기본 템플릿 비교
Dataflow에는 새로운 Flex 템플릿과 기본 템플릿의 두 가지 유형의 템플릿이 지원됩니다. 새 Dataflow 템플릿을 만들 때는 이를 Flex 템플릿으로 만드는 것이 좋습니다.
Flex 템플릿의 경우 Cloud Storage의 템플릿 사양 파일과 함께 파이프라인이 Artifact Registry에 Docker 이미지로 패키징됩니다. 템플릿 사양에는 Docker 이미지에 대한 포인터가 포함됩니다. 템플릿을 실행할 때 Dataflow 서비스는 런처 VM을 시작하고, Docker 이미지를 가져오고, 파이프라인을 실행합니다. 실행 그래프는 사용자가 제공하는 런타임 매개변수를 기반으로 동적으로 빌드됩니다. API를 사용하여 Flex 템플릿을 사용하는 작업을 실행하려면 projects.locations.flexTemplates.launch 메서드를 사용하세요.
기본 템플릿에는 Dataflow 작업 그래프의 JSON 직렬화가 포함됩니다. 파이프라인의 코드는 ValueProvider 인터페이스에서 모든 런타임 매개변수를 래핑해야 합니다. 이 인터페이스에서는 사용자가 템플릿을 배포할 때 매개변수 값을 지정할 수 있습니다. API를 사용하여 기본 템플릿을 사용하려면 projects.locations.templates API 참조 문서를 확인하세요.
Flex 템플릿은 기본 템플릿에 비해 다음과 같은 이점이 있습니다.
기본 템플릿과 달리 Flex 템플릿은 입력 매개변수를 위한 ValueProvider 인터페이스가 필요하지 않습니다. 모든 Dataflow 소스 및 싱크가 ValueProvider를 지원하지는 않습니다.
기본 템플릿에 정적 작업 그래프가 포함되지만 Flex 템플릿은 작업 그래프를 동적으로 생성할 수 있습니다. 예를 들어 템플릿이 입력 매개변수에 따라 서로 다른 I/O 커넥터를 선택할 수 있습니다.
Flex 템플릿이 파이프라인 생성 중 가상 머신(VM)에서 전처리를 수행할 수 있습니다. 예를 들어 입력 매개변수 값을 검증할 수 있습니다.
템플릿 워크플로
Dataflow 템플릿 사용에는 다음과 같은 주요 단계가 포함됩니다.
개발자가 개발 환경을 설정하고 파이프라인을 개발합니다. 이 환경에는 Apache Beam SDK와 기타 종속 항목이 포함됩니다.
템플릿 유형에 따라 다음과 같이 Flex 또는 기본 템플릿을 사용합니다.
Flex 템플릿의 경우에는 개발자가 파이프라인을 Docker 이미지에 패키징하고, 이미지를 Artifact Registry에 푸시하고, 템플릿 사양 파일을 Cloud Storage에 업로드합니다.
기본 템플릿의 경우에는 개발자가 파이프라인을 실행하고, 템플릿 파일을 만들고, 템플릿을 Cloud Storage에 스테이징합니다.
다른 사용자는 Dataflow 서비스에 요청을 제출하여 템플릿을 실행합니다.
Dataflow가 템플릿에서 파이프라인을 만듭니다. 파이프라인 실행이 시작되는 데 최대 5~7분이 걸릴 수 있습니다.
IAM 권한 설정
템플릿에서 실행되는 작업을 포함하여 Dataflow 작업에는 다음 2개의 IAM 서비스 계정이 사용됩니다.
Dataflow 서비스는 Dataflow 서비스 계정을 사용하여 VM 만들기와 같이 Google Cloud 리소스를 조작합니다.
Dataflow 작업자 VM은 작업자 서비스 계정을 사용하여 파이프라인의 파일 및 기타 리소스에 액세스합니다. 이 서비스 계정은 템플릿에 사용되는 소스와 싱크를 포함하여 파이프라인 작업이 참조하는 모든 리소스에 대한 액세스 권한이 필요합니다. 자세한 내용은 Google Cloud 리소스에 액세스를 참조하세요.
이러한 두 서비스 계정에 적절한 역할이 있는지 확인합니다. 자세한 내용은 Dataflow 보안 및 권한을 참조하세요.
Apache Beam SDK 버전 요구사항
템플릿을 직접 만들려면 사용 중인 Apache Beam SDK 버전이 템플릿 만들기를 지원하는지 확인합니다.
Java
Java용 Apache Beam SDK 2.x로 템플릿을 만들려면 버전 2.0.0-beta3 이상이 필요합니다.
Python
Python용 Apache Beam SDK 2.x로 템플릿을 만들려면 버전 2.0.0 이상이 필요합니다.
Google Cloud CLI를 사용하여 템플릿을 실행하려면 Google Cloud CLI 버전 138.0.0 이상이 필요합니다.
템플릿 확장
오픈소스 Dataflow 템플릿을 확장하여 자체 템플릿을 빌드할 수 있습니다. 예를 들어 고정된 기간을 사용하는 템플릿의 경우 해당 기간 이외에 도착하는 데이터가 삭제될 수 있습니다. 이 동작을 방지하려면 템플릿 코드를 기본으로 사용하고 코드를 수정하여 .withAllowedLateness 작업을 호출합니다.
[[["이해하기 쉬움","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-04-21(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)"]]