{"data":{"slug":"github-google-skills-skills-cloud-managed-airflow-dag-authoring-84e4aedeb73e","title":"GCP Managed Airflow DAG Authoring Guide","summary":"Author and validate Apache Airflow DAGs for GCP Managed Service for Apache Airflow (MSAA) environments, ensuring compatibility and correctness before deployment.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-managed-airflow-dag-authoring-84e4aedeb73e","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-managed-airflow-dag-authoring-84e4aedeb73e","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-managed-airflow-dag-authoring-84e4aedeb73e.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-managed-airflow-dag-authoring-84e4aedeb73e\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any `gcloud`, REST API, or MCP command, you MUST read [Usage Attribution](references\/attribution.md). For commands executed directly in the terminal, prefix `gcloud` with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:managed-airflow-dag-authoring)\"` and append `agent-skills\/1.0 (skill:managed-airflow-dag-authoring)` to `User-Agent` headers. Before writing any DAG code, you MUST understand the constraints (e.g., version of Airflow) and capabilities of your target environment if the user is willing to provide them.","instructions":"---\nname: managed-airflow-dag-authoring\ndescription: >-\n  Provides guidance for authoring Apache Airflow DAGs in Managed Service for\n  Apache Airflow (MSAA; formerly Cloud Composer). Covers environment context\n  discovery, Airflow 2 vs 3 compatibility, authoring best practices, and local\/remote\n  validation processes. Use when creating or extending an Airflow DAG. Don't\n  use when authoring Python code unrelated to Airflow DAGs.\nmetadata:\n  version: \"1.0.1\"\n  category: BigDataAndAnalytics\n---\n\n# GCP Managed Airflow DAG Authoring Guide\n\nThis skill guides you through authoring and validating Apache Airflow DAGs for\nManaged Service for Apache Airflow (MSAA; formerly Cloud Composer) environments.\n\n--------------------------------------------------------------------------------\n\n## Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read [Usage Attribution](references\/attribution.md). For commands executed\ndirectly in the terminal (never in generated scripts, Terraform, or user code),\nprefix `gcloud` with\n`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:managed-airflow-dag-authoring)\"`\nand append `agent-skills\/1.0 (skill:managed-airflow-dag-authoring)` to `User-Agent` headers.\n\n## Phase 1: Context Discovery\n\nBefore writing any DAG code, you MUST understand the constraints (e.g. version\nof Airflow) and capabilities of your target environment if user is willing to\nprovide them.\n\n### 1.1 Identify Target Environment & Access\n\nDetermine if you have direct access to the target Managed Airflow environment,\nlocal development environment or if you are working offline (only changing local\nfiles without validation).\n\n*   **If environment access is available:** Use `gcloud` to inspect the\n    environment (see Section 1.3).\n*   **If offline:** Rely on user provided details.\n\n### 1.2 Identify Development Environment\n\nDetermine if a local development environment is available.\n\n*   Check if `composer-dev` CLI is installed.\n*   Check if a local Python environment with `airflow` is available.\n\n### 1.3 Inspect Target Environment (if available and requested)\n\nRun the following commands to discover version constraints:\n\n1.  **Get Airflow\/Image Version:**\n\n    ```bash\n    gcloud composer environments describe {env_name} \\\n        --location {region} \\\n        --format=\"value(config.softwareConfig.imageVersion)\"\n    ```\n\n2.  **Get Installed Packages (Versions):**\n\n    ```bash\n    gcloud composer environments describe {env_name} \\\n        --location {region} \\\n        --format=\"value(config.softwareConfig.pypiPackages)\"\n    ```\n\n3.  **Get DAGs GCS Bucket:**\n\n    ```bash\n    gcloud composer environments describe {env_name} \\\n        --location {region} \\\n        --format=\"value(config.dagGcsPrefix)\"\n    ```\n\n--------------------------------------------------------------------------------\n\n## Phase 2: DAG Authoring Best Practices\n\n### 2.1 General Airflow Best Practices\n\n*   **Idempotency:** Every task SHOULD be idempotent. Running it multiple times\n    with the same inputs (e.g., execution date) SHOULD produce the same result\n    and not duplicate data.\n*   **No Top-Level Code Execution:** Do NOT execute database queries, external\n    API calls, or heavy computations at the top level of the DAG file (outside\n    of tasks\/operators). This code runs every few seconds during DAG parsing and\n    will degrade performance.\n*   **Explicit Catchup:** Always set `catchup=False` in the DAG definition\n    unless historical backfilling is explicitly required.\n*   **Use Airflow Variables\/Connections:** Never hardcode credentials or\n    environment-specific configs. Use `Variable.get()` (with\n    `deserialize_json=True` if applicable) and `BaseHook.get_connection()`.\n    Access variables via Jinja templates (e.g., `{{ var.value.my_var }}`) to\n    avoid database calls during DAG parsing.\n\n### 2.2 Airflow 2 vs Airflow 3 Compatibility\n\nUse managed-airflow-migrations skill to navigate adjusting the code to\nspecific target Airflow version.\n\n--------------------------------------------------------------------------------\n\n## Phase 3: Validation Process\n\nYou MUST validate DAGs before concluding your task.\n\n### 3.1 Local Validation (Offline\/Pre-deployment)\n\n#### 3.1.1 Static Analysis & Linting\n\nUse `ruff` or `pylint` if available.\n\n```bash\nruff check path\/to\/dag.py\n```\n\n*   If targeting Airflow 3, check with Airflow 3 rules if rulesets are\n    available.\n\n#### 3.1.2 Local Dev Environment (`composer-dev`)\n\nIf the user has `composer-dev` configured:\n\n1.  Copy the DAG to the local directory with DAGs:\n\n    ```bash\n    cp path\/to\/dag.py $(composer-dev describe {local_env} --format=\"value(dags_directory)\")\n    ```\n\n2.  Verify parsing:\n\n    ```bash\n    composer-dev run-airflow-cmd {local_env} dags list-import-errors\n    ```\n\n### 3.2: Target Environment Validation\n\nOnly perform these steps if you have GCP access and are authorized to deploy to\na target environment.\n\n### 3.2.1 Deploy to GCS\n\nUpload the DAG to the target environment's GCS bucket:\n\n```bash\ngcloud storage cp path\/to\/dag.py gs:\/\/{target_bucket}\/dags\/\n```\n\n### 3.2.2 Verify via Airflow CLI\n\nWait 1-2 minutes for the scheduler to parse the file, then run:\n\n1.  **Check for Import Errors:**\n\n    ```bash\n    gcloud composer environments run {env_name} \\\n        --location {region} \\\n        dags list-import-errors\n    ```\n\n*Pass Criteria:* Output should be \"No data found\" or empty.\n\n2.  **Verify DAG is Listed:**\n\n    ```bash\n    gcloud composer environments run {env_name} \\\n        --location {region} \\\n        dags list | grep {dag_id}\n    ```\n\n### 3.2.3 Monitor Cloud Logging\n\nCheck for runtime parsing errors in Cloud Logging:\n\n```query\nresource.type=\"cloud_composer_environment\"\nresource.labels.environment_name=\"{env_name}\"\nlog_id(\"airflow-scheduler\")\nseverity>=ERROR\ntextPayload:\"{dag_file_name}\"\n```\n\n--------------------------------------------------------------------------------\n\n## Definition of Done\n\n*   DAG code adheres to Airflow version constraints of the target environment.\n*   DAG code follows best practices (no top-level execution, idempotent if\n    possible).\n*   DAG parses locally without import errors.\n*   (If environment is available) DAG is deployed to the target environment and\n    verified to have no import errors.\n","use_cases":["Creating or extending an Airflow DAG in a GCP Managed Airflow environment","Validating DAGs before deployment to ensure compatibility and correctness"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/managed-airflow-dag-authoring\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T18:52:13.000000Z","updated_at":"2026-11-17T15:28:10.000000Z","seo_title":"GCP Managed Airflow DAG Authoring Guide","seo_description":"Learn how to author and validate Apache Airflow DAGs in GCP Managed Service for Apache Airflow (MSAA) environments.","seo_keywords":["GCP Airflow DAG authoring","Managed Airflow DAG validation","Cloud Composer DAG best practices","Airflow DAG deployment guide"]}}