GCP_PROJECT_ID は、VM と DAG を実行する環境が配置されているプロジェクトのプロジェクト ID に置き換えます。
importdatetimeimportairflowfromairflow.providers.ssh.operators.sshimportSSHOperatorfromairflow.providers.google.cloud.hooks.compute_sshimportComputeEngineSSHHookGCE_INSTANCE='example-compute-instance'GCE_ZONE='us-central1-a'GCP_PROJECT_ID='example-project'withairflow.DAG('composer_compute_ssh_dag',start_date=datetime.datetime(2022,1,1))asdag:ssh_task=SSHOperator(task_id='composer_compute_ssh_task',ssh_hook=ComputeEngineSSHHook(instance_name=GCE_INSTANCE,zone=GCE_ZONE,project_id=GCP_PROJECT_ID,use_oslogin=True,use_iap_tunnel=False,use_internal_ip=True),command='echo This command is executed from a DAG',dag=dag)
[[["わかりやすい","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-02-19 UTC。"],[[["This page provides instructions on how to connect to a Compute Engine VM from a Directed Acyclic Graph (DAG)."],["The `ComputeEngineSSHHook` is used within the `ssh_hook` parameter of the `SSHOperator` to establish the connection to the Compute Engine VM."],["An example demonstrates using `SSHOperator` to execute a command on a Compute Engine VM instance."],["To make it work, users must replace `GCE_INSTANCE`, `GCE_ZONE`, and `GCP_PROJECT_ID` with their respective values."],["The content shown on this page is currently for Cloud Composer 2, and it is not yet revised for Cloud Composer 3."]]],[]]