// POST https://composer.googleapis.com/v1/{environment=projects/*/locations/*/environments/*}:executeAirflowCommand{"environment":"projects/example-project/locations/us-central1/environments/example-environment","command":"dags","subcommand":"list","parameters":["-o json","--verbose"]}
// POST https://composer.googleapis.com/v1/{environment=projects/*/locations/*/environments/*}:pollAirflowCommand{"executionId":"a117da94-355d-4ad4-839e-ac39ccb0bf48","pod":"airflow-webserver-66d96b858f-tn96b","podNamespace":"airflow-2-10-2-build-13-226523e4","nextLineNumber":1}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[[["\u003cp\u003eThis document outlines how to use the Apache Airflow command-line interface (CLI) within Google Cloud Composer environments, specifically noting that the current content is for Cloud Composer 2, which only supports Airflow 2 CLI syntax.\u003c/p\u003e\n"],["\u003cp\u003eTo execute Airflow CLI commands, users must employ the \u003ccode\u003egcloud composer environments run\u003c/code\u003e command, specifying the environment name, location, and the desired Airflow CLI subcommand and its arguments, separated by a \u003ccode\u003e--\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFor Cloud Composer versions 2.4.0 and later, Airflow CLI commands can be run directly on private IP environments without needing access to the cluster's control plane; however, in earlier versions, such access was required.\u003c/p\u003e\n"],["\u003cp\u003eAlternatively, beginning with Cloud Composer version 2.4.0, Airflow CLI commands can be executed via the Cloud Composer API using the \u003ccode\u003eenvironments.executeAirflowCommand\u003c/code\u003e request, allowing for remote command execution and status monitoring through \u003ccode\u003ePollAirflowCommand\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTroubleshooting tips are provided for network connectivity issues, highlighting that a lack of connectivity to the cluster control plane may manifest as an "i/o timeout" error when running \u003ccode\u003egcloud composer environments run\u003c/code\u003e or \u003ccode\u003ekubectl\u003c/code\u003e commands, along with the specific steps needed to resolve it.\u003c/p\u003e\n"]]],[],null,["\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\n**Cloud Composer 3** \\| [Cloud Composer 2](/composer/docs/composer-2/access-airflow-cli \"View this page for Cloud Composer 2\") \\| [Cloud Composer 1](/composer/docs/composer-1/access-airflow-cli \"View this page for Cloud Composer 1\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nApache Airflow has a command-line interface (CLI) that you can use to perform\ntasks such as triggering and managing DAGs, getting information about DAG runs\nand tasks, adding and deleting connections and users.\n\nSupported Airflow CLI commands\n\nAirflow uses [Airflow 2 CLI syntax](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html), which is described in the\nAirflow documentation.\n\n\nFor a full list of supported Airflow CLI commands, see the reference for the\n[`gcloud composer environments run`](/sdk/gcloud/reference/composer/environments/run#SUBCOMMAND) command.\n\nBefore you begin\n\n- You must have [permissions](/composer/docs/composer-3/access-control#cli) to use\n Google Cloud CLI with Cloud Composer and run Airflow CLI\n commands.\n\n | **Caution:** Users with the `composer.environments.executeairflowcommand` permission can execute Python code available to Airflow components on behalf of the environment's service account. For more information, see [Access control](/composer/docs/composer-3/access-control#service-account-security).\n- Airflow CLI commands consume the `environments.executeAirflowCommand`\n [quota](/composer/quotas).\n\n | **Important:** If you want to trigger a large number of DAGs, we recommend to do it [with Airflow REST API](/composer/docs/composer-3/access-airflow-api#call-api). Triggering DAGs through Google Cloud CLI might cause your environment to reach the quota limit, and as a result, Airflow CLI commands will no longer be executed.\n- It is not possible to run Airflow CLI commands through `kubectl` in\n Cloud Composer 3. This approach was deprecated and is required only for\n Cloud Composer versions earlier than 2.4.0.\n\nRun Airflow CLI commands\n\nTo run Airflow CLI commands in your environments, use gcloud CLI: \n\n gcloud composer environments run \u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e \\\n --location \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n \u003cvar translate=\"no\"\u003eSUBCOMMAND\u003c/var\u003e \\\n -- \u003cvar translate=\"no\"\u003eSUBCOMMAND_ARGUMENTS\u003c/var\u003e\n\nReplace the following :\n\n- `ENVIRONMENT_NAME`: the name of your environment.\n- `LOCATION`: the region where the environment is located.\n- `SUBCOMMAND`: one of the [supported Airflow CLI commands](/sdk/gcloud/reference/composer/environments/run#SUBCOMMAND).\n- `SUBCOMMAND_ARGUMENTS` with arguments for the Airflow CLI command.\n\nSub-command arguments separator\n\nSeparate the arguments for the specified Airflow CLI command with `--`:\n\n\n- Specify compound CLI commands as a sub-command.\n- Specify any arguments for compound commands as sub-command arguments, after a `--` separator.\n\nExample: \n\n gcloud composer environments run example-environment \\\n dags list -- --output=json\n\n\u003cbr /\u003e\n\n\nDefault location\n\nMost `gcloud composer` commands require a location. You can specify the\nlocation with the `--location` flag, or by\n[setting the default location](/composer/docs/gcloud-installation#set-default).\n\nFor example, to trigger a DAG named `sample_quickstart` with the ID `5077` in\nyour Cloud Composer environment:\n\n\n gcloud composer environments run example-environment \\\n --location us-central1 dags trigger -- sample_quickstart \\\n --run-id=5077\n\n\u003cbr /\u003e\n\n\nRun Airflow CLI commands through Cloud Composer API\n\nIn Cloud Composer 3, you can run Airflow CLI commands through\nCloud Composer API.\n\n\nExecute a command\n\nConstruct an [`environments.executeAirflowCommand`](/composer/docs/reference/rest/v1/projects.locations.environments/executeAirflowCommand) API request: \n\n {\n \"environment\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e/environments/\u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e\",\n \"command\": \"\u003cvar translate=\"no\"\u003eAIRFLOW_COMMAND\u003c/var\u003e\",\n \"subcommand\": \"\u003cvar translate=\"no\"\u003eAIRFLOW_SUBCOMMAND\u003c/var\u003e\",\n \"parameters\": [\n \"\u003cvar translate=\"no\"\u003eSUBCOMMAND_PARAMETER\u003c/var\u003e\"\n ]\n }\n\nReplace the following:\n\n- `PROJECT_ID`: the [Project ID](/resource-manager/docs/creating-managing-projects).\n- `LOCATION`: the region where the environment is located.\n- `ENVIRONMENT_NAME`: the name of your environment.\n- `AIRFLOW_COMMAND`: Airflow CLI command that you want to execute, such as `dags`.\n- `AIRFLOW_SUBCOMMAND`: Sub-command for the Airflow CLI command that you want to execute, such as `list`.\n- (optional) `SUBCOMMAND_PARAMETER`: Parameters for the sub-command. If you want to use more than one parameter, add more items to the list.\n\nExample: \n\n // POST https://composer.googleapis.com/v1/{environment=projects/*/locations/*/environments/*}:executeAirflowCommand\n {\n \"environment\": \"projects/example-project/locations/us-central1/environments/example-environment\",\n \"command\": \"dags\",\n \"subcommand\": \"list\",\n \"parameters\": [\n \"-o json\",\n \"--verbose\"\n ]\n }\n\nPoll command status\n\nAfter you execute an Airflow CLI command through Cloud Composer API, check if\nthe command was successfully completed by making a\n[PollAirflowCommand](/composer/docs/reference/rest/v1/projects.locations.environments/pollAirflowCommand) request and inspecting the\nfields in `exitInfo` for errors and status codes. The `output` field contains\nlog lines.\n| **Note:** You can also stop executing a command with [StopAirflowCommand](/composer/docs/reference/rest/v1/projects.locations.environments/stopAirflowCommand).\n\nTo get the command execution status and fetch logs, provide `executionId`,\n`pod`, and `podNamespace` values returned by `ExecuteAirflowCommandRequest`:\n\nExample: \n\n // POST https://composer.googleapis.com/v1/{environment=projects/*/locations/*/environments/*}:pollAirflowCommand\n {\n \"executionId\": \"a117da94-355d-4ad4-839e-ac39ccb0bf48\",\n \"pod\": \"airflow-webserver-66d96b858f-tn96b\",\n \"podNamespace\": \"airflow-2-10-2-build-13-226523e4\",\n \"nextLineNumber\": 1\n }\n\n\nWhat's next\n\n- [Access Airflow UI](/composer/docs/composer-3/access-airflow-web-interface)\n- [Access control (Airflow CLI)](/composer/docs/composer-3/access-control#cli)"]]