upgrading-mwaa-environments

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Upgrading MWAA Environments

升级 MWAA 环境

AWS MCP server (optional but recommended): running the AWS CLI commands in this skill through the AWS MCP server gives sandboxed execution and audit logging. Every command here also works with the plain AWS CLI, so the skill does not require the MCP server or any MCP-only tools.
Upgrade an MWAA provisioned environment to any newer, MWAA-supported Airflow version: within 2.x, within 3.x, or across the 2.x-to-3.x boundary. The target is a parameter. A path planner computes an ordered version-jump list from (source, target); the latest 2.11.x stepping-stone version and a Python-line transition step are inserted only when the path requires them. A deployment approach is selected by whether historical run data must be preserved and whether the same environment (its URL/ARN) must be kept: a new-environment upgrade (
new-environment
), a rehearsed in-place upgrade validated on a test copy first (
in-place-rehearsed
), or a direct in-place upgrade (
in-place-direct
).
Execution note — poll in discrete steps: whenever you wait for an AWS operation to reach a terminal or ready state, issue one status check per call and decide in your own loop whether to check again. Never block a single command or script on the wait (no
while
+
sleep
until done), regardless of the operation or how long it takes.
AWS MCP 服务器(可选但推荐): 通过 AWS MCP 服务器运行本技能中的 AWS CLI 命令可获得沙箱执行能力和审计日志。此处的所有命令也可直接使用普通 AWS CLI 运行,因此本技能不强制要求 MCP 服务器或任何仅 MCP 可用的工具。
将 MWAA 预配置环境升级到任何 MWAA 支持的更新 Airflow 版本:支持 2.x 版本内、3.x 版本内或跨 2.x 到 3.x 大版本升级。目标版本为参数输入。路径规划器会根据(源版本,目标版本)计算有序的版本跳转列表;仅当路径需要时,才会插入最新的 2.11.x 垫脚石版本和 Python 版本过渡步骤。根据是否需要保留历史运行数据、是否需要保留相同环境(其 URL/ARN)选择部署方案:新环境升级(
new-environment
)、先在测试副本上验证的演练式原地升级(
in-place-rehearsed
),或直接原地升级(
in-place-direct
)。
执行注意事项——分步骤轮询: 每当你等待 AWS 操作到达终态或就绪状态时,每次调用仅执行一次状态检查,并在你自己的循环中决定是否再次检查。永远不要在单个命令或脚本中阻塞等待(不要用
while
+
sleep
直到完成),无论操作是什么、需要多长时间。

Guardrail — where this skill's own files live (MCP vs local install)

防护规则——本技能自身文件的存放位置(MCP 与本地安装)

This skill can be loaded two ways, and they resolve the skill's own bundled files from different places. Determine how the skill was loaded before reading a reference:
  • Loaded through the AWS MCP
    retrieve_skill
    tool:
    The skill is not installed on the local filesystem. You MUST fetch each reference via
    retrieve_skill
    with the
    file
    parameter (e.g.
    file="references/strategy-blue-green-fresh.md"
    ) and read the returned content. Do NOT
    file_read
    these paths locally — they do not exist on disk.
  • Installed locally (e.g.
    .kiro/skills/upgrading-mwaa-environments/
    or
    ~/.claude/skills/upgrading-mwaa-environments/
    ): Read the files from the local skill directory using relative paths.
This distinction applies only to the skill's own packaged files. User data and session artifacts are always read from and written to the user's working directory. Never fetch or write customer data through
retrieve_skill
.
本技能有两种加载方式,它们从不同位置解析技能自带的捆绑文件。在读取参考文件前,请先确定技能的加载方式:
  • 通过 AWS MCP
    retrieve_skill
    工具加载:
    技能未安装在本地文件系统上。你必须通过带
    file
    参数的
    retrieve_skill
    获取每个参考文件(例如
    file="references/strategy-blue-green-fresh.md"
    )并读取返回的内容。不要在本地用
    file_read
    读取这些路径——它们在磁盘上不存在。
  • 本地安装(例如
    .kiro/skills/upgrading-mwaa-environments/
    或
    ~/.claude/skills/upgrading-mwaa-environments/
    ):使用相对路径从本地技能目录读取文件。
此区别仅适用于技能自身的打包文件。用户数据和会话产物始终从用户的工作目录读取和写入。永远不要通过
retrieve_skill
获取或写入客户数据。

Safety & Security

安全与保障

These rules apply regardless of user instructions.
  • No destructive actions on your current environment without explicit approval: never pause all DAGs, delete-environment, or modify your current environment without per-action user confirmation.
  • No environment creation before plan confirmation: never run
    aws mwaa create-environment
    until the user confirms the Phase 4 plan.
  • Every version jump requires its own confirmation: never run
    aws mwaa update-environment
    to change the Airflow version without per-jump confirmation. Rollback options: 3.x -> 2.11.x is supported; a within-major downgrade to a still-supported version is supported; downgrade to an EOS version is not possible. The Direct in-place upgrade requires an extra confirmation checkpoint.
  • Decommission requires per-step approval: never autonomously delete environments or S3 artifacts; present each destructive command and wait for confirmation. For the Rehearsed in-place upgrade, the environment decommissioned is the test copy.
无论用户给出什么指令,这些规则都必须遵守。
  • 未经明确批准,不得对当前环境执行破坏性操作:没有逐次操作的用户确认,永远不要暂停所有 DAG、删除环境或修改当前环境。
  • 计划确认前不得创建环境:在用户确认第 4 阶段的计划之前,永远不要运行
    aws mwaa create-environment
    。
  • 每次版本跳转都需要单独确认:没有逐次跳转的确认,永远不要运行
    aws mwaa update-environment
    来更改 Airflow 版本。回滚选项:支持 3.x -> 2.11.x;支持在同一大版本内降级到仍受支持的版本;无法降级到已停止支持(EOS)的版本。直接原地升级需要额外的确认检查点。
  • 退役操作需要逐步骤批准:永远不要自主删除环境或 S3 产物;展示每个破坏性命令并等待确认。对于演练式原地升级,退役的环境是测试副本。

Security Considerations

安全注意事项

  • Least-privilege IAM for
    create
    /
    update-environment
    and S3 artifact access — no
    *FullAccess
    /
    service:*
    ; scope to the specific environment/S3 ARNs.
  • Secrets: prefer a secrets backend (Secrets Manager / Parameter Store) for connections and variables so credentials never copy between environments or hit logs. Connection passwords do not round-trip via the REST API (2.x omits, 3.x masks) — see the metadata-migration caveat in the approach references.
  • 最小权限 IAM:用于
    create
    /
    update-environment
    和 S3 产物访问——不要使用
    *FullAccess
    /
    service:*
    ;权限范围限定为特定的环境/S3 ARN。
  • 密钥管理:连接和变量优先使用密钥后端(Secrets Manager / Parameter Store),这样凭证永远不会在环境之间复制,也不会出现在日志中。连接密码无法通过 REST API 往返获取(2.x 会省略,3.x 会掩码)——参见方案参考中的元数据迁移注意事项。

Reference Documentation

参考文档

  • discovery-preflight.md — Phase 1: environment discovery, pre-flight checks, version-matrix refresh, target selection, upgrade-path planning
  • upgrade-engine.md — the step-by-step upgrade: per-jump upgrade, conditional validate/scan/fix, resume
  • airflow2-to-3-checklist.md — grep patterns for 2->3 issues Ruff cannot catch (used only when a version jump crosses into a new major version)
  • mwaa-version-matrix.md — runtime-first version/Python/EOS matrix, version-jump rules, providers, unsupported features
  • airflow2-to-3-quick-reference.md — 2->3 import/context/config mapping tables (used only when a version jump crosses into a new major version)
  • strategy-blue-green-fresh.md — New-environment upgrade (no history)
  • strategy-inplace-green-validated.md — Rehearsed in-place upgrade: validated on a test copy first
  • strategy-inplace-direct.md — Direct in-place upgrade (unrecommended)
For deeper detail beyond embedded references, fetch at runtime:
  • discovery-preflight.md — 第 1 阶段:环境发现、预检查、版本矩阵刷新、目标版本选择、升级路径规划
  • upgrade-engine.md — 分步升级:逐次跳转升级、条件式验证/扫描/修复、恢复执行
  • airflow2-to-3-checklist.md — Ruff 无法捕获的 2->3 问题的 grep 匹配模式(仅在版本跳转跨越大版本时使用)
  • mwaa-version-matrix.md — 以运行时为优先的版本/Python/EOS 矩阵、版本跳转规则、提供商、不支持的功能
  • airflow2-to-3-quick-reference.md — 2->3 导入/上下文/配置映射表(仅在版本跳转跨越大版本时使用)
  • strategy-blue-green-fresh.md — 新环境升级(不保留历史)
  • strategy-inplace-green-validated.md — 演练式原地升级:先在测试副本上验证
  • strategy-inplace-direct.md — 直接原地升级(不推荐)
如需超出嵌入式参考的更详细信息,可在运行时获取:

Phase 0: Re-entry Check

第 0 阶段:重入检查

At every invocation, check for
.mwaa-upgrade-plan-<env-name>.md
in the workspace root (where
<env-name>
is the source environment name). Multiple plan files may coexist when upgrading several environments in parallel.
  • If exists: Load the plan, report source, target, chosen approach, and the position
    (working_on, current_jump, jump_status)
    . Resume the engine (upgrade-engine.md) on the recorded environment at the recorded version-jump index and status:
    upgrading
    -> re-poll or re-issue the pending
    update-environment
    ;
    validating
    -> re-run the conditional validate/scan/fix loop for that version jump. For a newly-created environment, the starting-version validation window (version jump 1's
    to
    ) corresponds to
    current_jump: 1, jump_status: validating
    ; resume it there. If no position is set, resume from the next incomplete phase. Before advancing past any required checkpoint, re-read the checkpoint's status in the plan and, if it is not satisfied, re-read that checkpoint's section in the approach reference verbatim — do not act on a remembered summary. Specifically: version jumps complete does NOT imply the test-run checkpoint passed. If the
    ## Test-run results
    section has any row not in SUCCESS or NEEDS-DECISION, that checkpoint is NOT-PASSED and blocks switchover (New-environment upgrade), the live upgrade (Rehearsed in-place upgrade — see
    live_upgrade_allowed
    ), or completion (Direct in-place upgrade), regardless of version-jump status or
    has_import_errors: false
    . Likewise a batch whose
    Monitored one full cycle?
    cell is not yes has not fully switched over.
Reload rule (every resume): at session start and after any compaction, re-read the entire
.mwaa-upgrade-plan-<env-name>.md
before taking any action; never act on a remembered or summarized version. This generalizes the remembered-summary rule above from required checkpoints to the whole plan.
Plan Reconciliation (run before resuming any work): verify the plan's self-consistency invariants (full list in plan-materialization.md): a checkpoint marked
PASSED
requires all its prerequisite Checklist items
DONE
/
SKIP
;
Where we are.test_run_checkpoint
must equal the Test-run results table (any
PENDING
row ->
NOT-PASSED
);
current_jump
/
jump_status
must match the Upgrade Path Status; for the Rehearsed in-place upgrade,
live_upgrade_allowed
must equal the test-run checkpoint. On ANY violation, do NOT trust the plan - establish ground truth with read-only
aws mwaa get-environment
,
/dags
, and
/health
, repair the plan to match reality, and record it in
Last updated
. If reality is ambiguous, ask the user. A stale
PASSED
checkpoint otherwise triggers a destructive next action: switchover + delete your current environment (New-environment upgrade), the irreversible live upgrade (Rehearsed in-place upgrade), or premature completion (Direct in-place upgrade).
  • If absent: Proceed to Phase 1.
每次调用时,检查工作区根目录下是否存在
.mwaa-upgrade-plan-<env-name>.md
(其中
<env-name>
是源环境名称)。并行升级多个环境时,可能会共存多个计划文件。
  • 如果存在:加载计划,报告源版本、目标版本、所选方案,以及位置
    (working_on, current_jump, jump_status)
    。在记录的环境上,按照记录的版本跳转索引和状态恢复升级引擎(upgrade-engine.md):
    upgrading
    -> 重新轮询或重新发起待处理的
    update-environment
    ;
    validating
    -> 重新运行该版本跳转的条件式验证/扫描/修复循环。对于新创建的环境,起始版本验证窗口(版本跳转 1 的
    to
    版本)对应
    current_jump: 1, jump_status: validating
    ;从该位置恢复。如果未设置位置,则从下一个未完成的阶段恢复。 在推进到任何必需检查点之前,请重新读取计划中该检查点的状态,如果未满足要求,请逐字重新读取方案参考中该检查点的章节——不要凭记忆的摘要行事。 特别说明:版本跳转完成并不意味着测试运行检查点已通过。如果
    ## Test-run results
    部分有任何行的状态不是 SUCCESS 或 NEEDS-DECISION,则该检查点未通过,会阻塞切换(新环境升级)、正式升级(演练式原地升级——参见
    live_upgrade_allowed
    )或完成(直接原地升级),无论版本跳转状态如何,也无论
    has_import_errors: false
    是否为真。同样,如果某个批次的
    Monitored one full cycle?
    单元格不是 yes,则该批次尚未完全切换。
重新加载规则(每次恢复时): 在会话开始时和任何压缩之后,在采取任何行动之前重新读取整个
.mwaa-upgrade-plan-<env-name>.md
;永远不要凭记忆或摘要版本行事。这将上述的记忆摘要规则从必需检查点推广到了整个计划。
计划核对(恢复任何工作前运行): 验证计划的自洽性不变量(完整列表见 plan-materialization.md):标记为
PASSED
的检查点要求其所有先决检查清单项都为
DONE
/
SKIP
;
Where we are.test_run_checkpoint
必须与测试运行结果表一致(任何
PENDING
行 ->
NOT-PASSED
);
current_jump
/
jump_status
必须与升级路径状态匹配;对于演练式原地升级,
live_upgrade_allowed
必须等于测试运行检查点的状态。如果出现任何不一致,不要信任计划——通过只读的
aws mwaa get-environment
、
/dags
和
/health
确定真实情况,修复计划以匹配现实,并在
Last updated
中记录。如果现实情况不明确,询问用户。否则,过时的
PASSED
检查点会触发破坏性的下一步操作:切换 + 删除当前环境(新环境升级)、不可逆的正式升级(演练式原地升级),或过早完成(直接原地升级)。
  • 如果不存在:进入第 1 阶段。

Phase 1: Discover + Plan Path + Pre-flight

第 1 阶段:发现 + 路径规划 + 预检查

Fetch and follow references/discovery-preflight.md. It runs environment discovery, pre-flight safety checks, version-matrix refresh, target selection, and upgrade-path planning (detection only — version jumps execute in Phase 7). Record every output into the plan now, because Phase 4 is what turns it into the durable plan file, and a compaction before Phase 4 would otherwise lose it:
  • discovered environment facts (Airflow version, S3 artifact paths + object versions, KmsKey, config options, DAG list, shared utilities);
  • the new-environment / test-copy S3 layout (New-environment upgrade, Rehearsed in-place upgrade);
  • pre-flight results (S3 versioning, target constraints, KMS key-policy reuse);
  • the selected target version;
  • the ordered upgrade path — per version jump
    from
    /
    to
    /
    python_change
    /
    crosses_major
    , with the latest-2.11.x stepping-stone version + Python-transition step inserted only when the source is not already 2.11.x.
获取并遵循 references/discovery-preflight.md。该阶段执行环境发现、预飞行安全检查、版本矩阵刷新、目标版本选择和升级路径规划(仅检测——版本跳转在第 7 阶段执行)。现在就将所有输出记录到计划中,因为第 4 阶段才会将其转换为持久化计划文件,否则第 4 阶段之前的压缩会丢失这些信息:
  • 发现的环境事实(Airflow 版本、S3 产物路径 + 对象版本、KmsKey、配置选项、DAG 列表、共享工具);
  • 新环境/测试副本的 S3 布局(新环境升级、演练式原地升级);
  • 预检查结果(S3 版本控制、目标版本约束、KMS 密钥策略复用);
  • 选定的目标版本;
  • 有序的升级路径——每个版本跳转为
    from
    /
    to
    /
    python_change
    /
    crosses_major
    ,仅当源版本不是 2.11.x 时,才会插入最新的 2.11.x 垫脚石版本 + Python 过渡步骤。

Phase 2: Choose the Upgrade Approach

第 2 阶段:选择升级方案

One question decides the safest approach; whether you keep the same environment (its URL and ARN) follows from it and is not a separate choice.
Do you need to keep your run history — the record of past DAG runs and task instances in the Airflow UI?
  • No, a clean slate is fine → New-environment upgrade (slug
    new-environment
    ). Build a brand-new environment on the target version and switch over to it. It gets a new URL and starts with no run history; your current environment keeps running untouched until you switch, so rolling back is just "don't switch."
  • Yes, keep it → Rehearsed in-place upgrade (slug
    in-place-rehearsed
    ). Upgrade your existing environment in place — same URL, full history kept. First rehearse the whole upgrade on a temporary test copy to catch problems safely. Use the Direct in-place upgrade (no test copy) only if the user explicitly declines the rehearsal.
Whether you keep the same environment (its URL and ARN) is a consequence, not an input: keeping your run history means upgrading your current environment in place (same URL and ARN), while the New-environment upgrade necessarily creates a new environment. This skill does not combine a new environment (a new URL and ARN) with preserved run history — if the user needs a new URL and ARN, run history is not carried over (New-environment upgrade).
ApproachHistoryURL/ARNYour current environment during the upgradeNew/test environment created atRecommended
New-environment upgradeDiscardedNewRuns until switchoverthe first version jump's targetYes
Rehearsed in-place upgradePreserved (snapshot)SameRehearsed on a test copy, then upgradedthe first version jump's targetYes
Direct in-place upgradePreserved (snapshot)SameUpgraded directlynoneNo
The New-environment upgrade and the Rehearsed in-place upgrade are both recommended; the user chooses by need. The Direct in-place upgrade is unrecommended and requires an extra confirmation checkpoint.
Guardrail: if the user picks the Rehearsed or Direct in-place upgrade and the environment has more than 50 DAGs or complex DAGs were detected in Phase 3, warn and recommend the New-environment upgrade instead. Do not block.
Record the chosen approach's slug (
new-environment
/
in-place-rehearsed
/
in-place-direct
) in the plan. The position (
working_on
,
current_jump
,
jump_status
) is initially unset.
一个问题决定了最安全的方案;是否保留相同环境(其 URL 和 ARN)是由此衍生的结果,不是独立的选择。
你是否需要保留运行历史——即 Airflow UI 中过去的 DAG 运行和任务实例的记录?
  • 不需要,全新开始即可 → 新环境升级(标识
    new-environment
    )。在目标版本上构建一个全新的环境,然后切换到它。它会有一个新的 URL,且没有任何运行历史;你的当前环境在切换前会一直正常运行,因此回滚就是“不切换”。
  • 需要保留 → 演练式原地升级(标识
    in-place-rehearsed
    )。原地升级现有环境——相同 URL,保留全部历史。首先在临时测试副本上演练整个升级过程,以安全地发现问题。仅当用户明确拒绝演练时,才使用直接原地升级(无测试副本)。
是否保留相同环境(其 URL 和 ARN)是结果而非输入:保留运行历史意味着原地升级当前环境(相同 URL 和 ARN),而新环境升级必然会创建一个新环境。本技能不会将新环境(新 URL 和 ARN)与保留运行历史结合起来——如果用户需要新的 URL 和 ARN,则运行历史不会被保留(新环境升级)。
方案历史记录URL/ARN升级期间你的当前环境新/测试环境创建时机是否推荐
新环境升级丢弃新的运行至切换时第一个版本跳转的目标版本是
演练式原地升级保留(快照)相同在测试副本上演练,然后升级第一个版本跳转的目标版本是
直接原地升级保留(快照)相同直接升级无否
新环境升级和演练式原地升级都是推荐方案;用户根据需求选择。直接原地升级不推荐,且需要额外的确认检查点。
防护规则:如果用户选择演练式或直接原地升级,且环境中有超过 50 个 DAG 或在第 3 阶段检测到复杂 DAG,应发出警告并推荐改用新环境升级。但不要阻塞用户操作。
将所选方案的标识(
new-environment
/
in-place-rehearsed
/
in-place-direct
)记录到计划中。位置(
working_on
、
current_jump
、
jump_status
)初始未设置。

Phase 3: Assess Compatibility

第 3 阶段:评估兼容性

  1. Compatibility scan (conditional on a cross-major version jump): If any version jump in the plan is
    crosses_major
    , run Ruff with AIR rules as a required checkpoint:
    ruff check --preview --select AIR .
    Report findings grouped by rule code. Ruff AIR rules cover 2-to-3 (AIR301/302/303/311/312) and 3.1 (AIR321, preview) API changes; they do NOT detect APIs removed between 2.x minor versions, nor 3.2-specific changes. The pre-cross deprecation-warning scan in the engine covers the 2.x-internal gap. If NO version jump is
    crosses_major
    (a within-major upgrade), the AIR scan is informational only; rely on the engine's generic
    DeprecationWarning
    scan instead.
    Version-aware severity for AIR311 (import path moves): AIR311 flags imports that moved to
    airflow.sdk
    (e.g.,
    airflow.datasets.Dataset
    ->
    airflow.sdk.Asset
    ). Severity depends on the target version:
    • Target 3.0.x or 3.1.x: soft deprecation — compatibility shims exist, old imports still work. Fix recommended but not blocking.
    • Target 3.2.1+: hard blocker — shim modules are fully removed (
      ModuleNotFoundError
      at parse time). Must fix before deploying to target.
    Always classify AIR311 as "must fix" when the target is 3.2.1+. The fixed code (
    from airflow.sdk import ...
    ) is AF3-only and cannot be deployed until after the cross-major version jump completes — see the two-phase deployment note in each approach reference.
    Patterns Ruff does NOT catch: The manual checklist (airflow2-to-3-checklist.md) includes patterns invisible to Ruff, notably
    _TaskDecorator.output
    (section 15) and standalone Airflow CLI in BashOperator (section 16). Always run the manual scan even when Ruff reports zero findings.
  2. Run manual scan using patterns from airflow2-to-3-checklist.md. Surface a metadata-DB warning (every approach, cross-major only): DAGs using metadata-DB access work on AF2 but break on AF3. Two categories:
    • ORM-access DAGs (
      settings.Session()
      ,
      provide_session
      — checklist section 1): must be redesigned to the REST API (webserver in-VPC, or
      invoke-rest-api
      with its low rate limit) or dropped.
    • CLI-access DAGs (
      airflow db ...
      in BashOperator — checklist section 16): redesign to the MWAA CLI endpoint (preferred, simpler) or REST API or drop. The agent must verify command availability on the target version via
      cheat-sheet
      before committing to this path. Record each affected DAG and its category in the plan (Phase 4).
  3. Check requirements.txt against the target version's constraints from mwaa-version-matrix.md.
  4. Secrets backend detection: Check for
    secrets.backend
    config override in environment configuration. If using Secrets Manager or Parameter Store, note that variables/connections are external and do not need migration. If NO secrets backend is configured, surface this to the user at plan time: connection passwords will NOT migrate via the REST API (2.x omits, 3.x masks), so password-bearing connections must be moved to a secrets backend or have their passwords re-entered out of band on the target — and variable values / connection
    extra
    transit
    --body
    /CLI args and the audit log during migration. Record this in the plan (Phase 4).
  5. Plugin inventory: If PluginsS3Path is set, list contents. Flag FAB/web-view plugins needing special attention.
  6. Classify each DAG by upgrade difficulty: Simple, Moderate, Complex.
  7. Group DAGs into batches (shared utilities in batch 0, simple first).
  1. 兼容性扫描(跨大版本跳转时的条件项): 如果计划中的任何版本跳转是
    crosses_major
    (跨大版本),则运行带 AIR 规则的 Ruff 作为必需检查点:
    ruff check --preview --select AIR .
    按规则代码分组报告发现的问题。Ruff AIR 规则涵盖 2 到 3(AIR301/302/303/311/312)和 3.1(AIR321,预览版)的 API 变更;它们不会检测 2.x 次版本之间移除的 API,也不会检测 3.2 特有的变更。引擎中的跨版本前弃用警告扫描覆盖了 2.x 内部的空白。如果没有版本跳转是
    crosses_major
    (同一大版本内升级),则 AIR 扫描仅作参考;请改用引擎的通用
    DeprecationWarning
    扫描。
    AIR311(导入路径移动)的版本感知严重程度: AIR311 标记已移动到
    airflow.sdk
    的导入(例如
    airflow.datasets.Dataset
    ->
    airflow.sdk.Asset
    )。严重程度取决于目标版本:
    • 目标 3.0.x 或 3.1.x: 软弃用——存在兼容垫片,旧导入仍然有效。建议修复但不阻塞。
    • 目标 3.2.1+: 硬阻塞——垫片模块已完全移除(解析时会出现
      ModuleNotFoundError
      )。必须在部署到目标版本之前修复。
    当目标版本为 3.2.1+ 时,始终将 AIR311 归类为“必须修复”。修复后的代码(
    from airflow.sdk import ...
    )仅适用于 AF3,在跨大版本跳转完成之前无法部署——参见每个方案参考中的两阶段部署说明。
    Ruff 无法捕获的模式: 手动检查清单(airflow2-to-3-checklist.md)包含 Ruff 无法识别的模式,特别是
    _TaskDecorator.output
    (第 15 节)和 BashOperator 中的独立 Airflow CLI(第 16 节)。即使 Ruff 报告零发现,也始终要运行手动扫描。
  2. 使用 airflow2-to-3-checklist.md 中的模式运行手动扫描。 提示元数据数据库警告(所有方案,仅跨大版本时): 使用元数据数据库访问的 DAG 在 AF2 上正常工作,但在 AF3 上会中断。分为两类:
    • ORM 访问 DAG(
      settings.Session()
      、
      provide_session
      ——检查清单第 1 节):必须重新设计为使用 REST API(VPC 内的 webserver,或速率限制较低的
      invoke-rest-api
      )或弃用。
    • CLI 访问 DAG(BashOperator 中的
      airflow db ...
      ——检查清单第 16 节):重新设计为使用 MWAA CLI 端点(首选,更简单)或 REST API,或弃用。Agent 必须在确定采用此路径前,通过
      cheat-sheet
      验证目标版本上的命令可用性。 将每个受影响的 DAG 及其类别记录到计划中(第 4 阶段)。
  3. 根据 mwaa-version-matrix.md 中目标版本的约束,检查 requirements.txt。
  4. 密钥后端检测:检查环境配置中是否有
    secrets.backend
    配置覆盖。如果使用 Secrets Manager 或 Parameter Store,请注意变量/连接是外部的,不需要迁移。如果未配置密钥后端,请在计划阶段向用户提示: 连接密码不会通过 REST API 迁移(2.x 会省略,3.x 会掩码),因此带密码的连接必须移至密钥后端,或在目标环境中通过带外方式重新输入密码——并且变量值/连接
    extra
    会在迁移过程中经过
    --body
    /CLI 参数和审计日志。将此记录到计划中(第 4 阶段)。
  5. 插件清单:如果设置了 PluginsS3Path,列出其内容。标记需要特别注意的 FAB/web-view 插件。
  6. 按升级难度对每个 DAG 进行分类:简单、中等、复杂。
  7. 将 DAG 分组为批次(共享工具在批次 0,简单的优先)。

Phase 4: Generate Upgrade Plan

第 4 阶段:生成升级计划

Write
.mwaa-upgrade-plan-<env-name>.md
to workspace root (where
<env-name>
is the source environment name discovered in Phase 1). Include:
  • Environment details (source name, source version, region) plus the target version and the full upgrade-path table
  • Chosen approach — its slug (
    new-environment
    /
    in-place-rehearsed
    /
    in-place-direct
    )
  • Pre-flight results (S3 versioning, constraints, upgrade-path status)
  • Docker validation status (pending)
  • Secrets backend detection results
  • Requirements changes needed
  • Cross-major only — metadata-DB-access findings (Phase 3 step 2): each DAG using metadata-DB access, categorized as ORM-access (redesign to REST API or drop) or CLI-access (redesign to MWAA CLI endpoint, or REST API, or drop); plus a PENDING post-fix re-scan checkpoint (Phase 5 step 2d). Omit when no version jump is
    crosses_major
    .
  • Approach-specific fields: New-environment upgrade — new environment name, new-environment S3 paths; Rehearsed in-place upgrade — test-copy env name, test-copy S3 paths; Direct in-place upgrade — none (in-place, no new/test environment)
  • Batch table with per-DAG status
Record the ordered upgrade path as a
## Upgrade Path
table:
JumpFrom → ToPython changeNew major versionStatus
1<jump.from> → <jump.to>yes/noyes/nopending
For the Rehearsed in-place upgrade (two environments — the test copy, then your current environment), give the upgrade-path table separate
Test copy status
and
Your current environment status
columns; mark the current-environment jumps
IRREVERSIBLE
.
将
.mwaa-upgrade-plan-<env-name>.md
写入工作区根目录(其中
<env-name>
是第 1 阶段发现的源环境名称)。包含以下内容:
  • 环境详情(源名称、源版本、区域)以及目标版本和完整的升级路径表
  • 所选方案——其标识(
    new-environment
    /
    in-place-rehearsed
    /
    in-place-direct
    )
  • 预检查结果(S3 版本控制、约束、升级路径状态)
  • Docker 验证状态(待处理)
  • 密钥后端检测结果
  • 需要的 requirements 变更
  • 仅跨大版本时——元数据数据库访问发现的问题(第 3 阶段步骤 2):每个使用元数据数据库访问的 DAG,分类为 ORM 访问(重新设计为 REST API 或弃用)或 CLI 访问(重新设计为 MWAA CLI 端点、REST API 或弃用);加上一个待处理的修复后重新扫描检查点(第 5 阶段步骤 2d)。如果没有版本跳转是
    crosses_major
    ,则省略此项。
  • 方案特定字段:新环境升级——新环境名称、新环境 S3 路径;演练式原地升级——测试副本环境名称、测试副本 S3 路径;直接原地升级——无(原地升级,无新/测试环境)
  • 带每个 DAG 状态的批次表
将有序的升级路径记录为
## Upgrade Path
表格:
跳转序号从 → 到Python 版本变更新大版本状态
1<jump.from> → <jump.to>是/否是/否待处理
对于演练式原地升级(两个环境——先测试副本,然后是当前环境),升级路径表应分别设置
测试副本状态
和
当前环境状态
列;将当前环境的跳转标记为
IRREVERSIBLE
(不可逆)。

Write out every checkpoint and record-section into the plan (mandatory)

将每个检查点和记录部分写入计划(强制要求)

Before presenting the plan, follow plan-materialization.md and generate every section it specifies, conforming to its
## Plan format contract
(fixed status vocabulary,
Last updated
line,
## Where we are
keys) and satisfying its
## Self-consistency invariants
: the
## Checklist
, every per-approach required checkpoint as its own PENDING entry, the pre-seeded
## Test-run results
and
## Switchover progress
(New-environment upgrade) tables, the
## Where we are
block, the parse-clean-vs-test-run-verified status vocabulary (
LOADED
vs
VERIFIED
), and the approach-specific sub-step decomposition rules. The plan is the durable, resumable source of truth: any step that exists only as prose in a approach reference — not as a discrete PENDING item here — WILL be skipped after compaction. Generate these sections BEFORE presenting the plan; a parse-clean signal (
has_import_errors: false
) does NOT satisfy the test-run checkpoint and must never be recorded as "validated" or "complete".
Present the plan to the user for confirmation before proceeding.
在展示计划之前,请遵循 plan-materialization.md,生成其指定的所有章节,符合其
## Plan format contract
(固定状态词汇、
Last updated
行、
## Where we are
键),并满足其
## Self-consistency invariants
:
## Checklist
、每个方案特定的必需检查点作为独立的待处理条目、预填充的
## Test-run results
和
## Switchover progress
(新环境升级)表格、
## Where we are
块、解析通过与测试运行验证的状态词汇(
LOADED
与
VERIFIED
),以及方案特定的子步骤分解规则。计划是持久的、可恢复的真实来源:任何仅在方案参考中以散文形式存在的步骤——而不是作为这里的离散待处理项——在压缩后会被跳过。在展示计划之前生成这些章节;解析通过的信号(
has_import_errors: false
)并不满足测试运行检查点的要求,绝不能被记录为“已验证”或“已完成”。
在继续之前,将计划呈现给用户确认。

Phase 5: Fix Code

第 5 阶段:修复代码

  1. Batch 0 (shared utilities): Fix shared modules first. Apply patterns from airflow2-to-3-quick-reference.md.
  2. Per batch (1..N): a. Run Ruff auto-fix:
    ruff check --preview --select AIR --fix --unsafe-fixes <files>
    b. Fix remaining issues per DAG using airflow2-to-3-quick-reference.md. c. Re-run Ruff to verify zero AIR violations. d. Re-scan the FIXED files (cross-major only) with the checklist section 15/16 greps — not just the originals.
    --unsafe-fixes
    can rewrite
    xcom_pull
    templates into
    <task>.output
    (AF3-invalid) without re-flagging it; this runtime break otherwise surfaces only at live parse. Fix hits and re-run Ruff. e. Save progress (see plan-materialization.md
    ## Saving progress
    ): mark each DAG
    DONE
    and update
    Last updated
    before starting the next batch.
  1. 批次 0(共享工具): 首先修复共享模块。应用 airflow2-to-3-quick-reference.md 中的模式。
  2. 逐批次(1..N): a. 运行 Ruff 自动修复:
    ruff check --preview --select AIR --fix --unsafe-fixes <files>
    b. 使用 airflow2-to-3-quick-reference.md 逐个 DAG 修复剩余问题。 c. 重新运行 Ruff 以验证零 AIR 违规。 d. (仅跨大版本时)重新扫描已修复的文件,使用检查清单第 15/16 节的 grep 模式——不仅仅是原始文件。
    --unsafe-fixes
    可能会将
    xcom_pull
    模板重写为
    <task>.output
    (在 AF3 中无效),而不会重新标记;否则这个运行时中断只会在实时解析时才会显现。修复发现的问题并重新运行 Ruff。 e. 保存进度(参见 plan-materialization.md 的
    ## Saving progress
    ):在开始下一个批次之前,将每个 DAG 标记为
    DONE
    并更新
    Last updated
    。

Phase 6: Local Validation via Docker (Recommended; Strongly Recommended for Cross-Major)

第 6 阶段:通过 Docker 进行本地验证(推荐;跨大版本时强烈推荐)

Uses
aws/amazon-mwaa-docker-images
to validate fixed code against the target version. This repo only provides images for Airflow 2.9.2 and newer. If the target version is below 2.9.2, skip Docker validation (log skip reason in the plan) and rely on the engine's live validation in Phase 7 instead.
Cross-major version jumps: When any version jump is
crosses_major
, Docker validation is strongly recommended. Ruff AIR rules miss several runtime-breaking patterns (e.g.,
_TaskDecorator.output
removal, fully-removed shim modules in 3.2.1+). Docker import validation catches these before live deployment, avoiding iterative fix-deploy-fail cycles on the remote environment. If Docker is skipped for a cross-major upgrade, log the skip reason AND warn that undetected runtime errors are likely.
  1. Check Docker availability:
    docker --version
    . If unavailable, user declines, or target < 2.9.2, log skip in plan with warning and proceed to Phase 7.
  2. Pull the target-version image (resolve the exact tag at runtime from the repo README).
  3. Validate requirements.txt: Mount into container, run install validation. If failures: report conflicts, suggest fixes, loop until passing or user skips.
  4. Validate plugins.zip (if present): Mount and run import validation.
  5. Validate DAG imports: Mount fixed DAGs, run parsing. If errors: return to Phase 5 for affected files, then re-validate.
  6. Save progress: mark Docker validation
    DONE
    or
    SKIP
    (with reason) and update
    Last updated
    .
使用
aws/amazon-mwaa-docker-images
针对目标版本验证修复后的代码。该仓库仅提供 Airflow 2.9.2 及更高版本的镜像。如果目标版本低于 2.9.2,跳过 Docker 验证(在计划中记录跳过原因),转而依赖第 7 阶段引擎的实时验证。
跨大版本跳转: 当任何版本跳转是
crosses_major
时,强烈推荐 Docker 验证。Ruff AIR 规则会遗漏几种破坏运行时的模式(例如
_TaskDecorator.output
移除、3.2.1+ 中完全移除的垫片模块)。Docker 导入验证可以在实时部署之前捕获这些问题,避免在远程环境上进行迭代的修复-部署-失败循环。如果跨大版本升级跳过了 Docker,请记录跳过原因并警告可能存在未检测到的运行时错误。
  1. 检查 Docker 可用性:
    docker --version
    。如果不可用、用户拒绝,或目标版本 < 2.9.2,在计划中记录跳过并附带警告,然后进入第 7 阶段。
  2. 拉取目标版本的镜像(在运行时从仓库 README 解析确切的标签)。
  3. 验证 requirements.txt:挂载到容器中,运行安装验证。如果失败:报告冲突,建议修复,循环直到通过或用户跳过。
  4. 验证 plugins.zip(如果存在):挂载并运行导入验证。
  5. 验证 DAG 导入:挂载修复后的 DAG,运行解析。如果有错误:返回第 5 阶段修复受影响的文件,然后重新验证。
  6. 保存进度:将 Docker 验证标记为
    DONE
    或
    SKIP
    (附带原因),并更新
    Last updated
    。

Phase 7: Deploy

第 7 阶段:部署

Dispatch to the approach-specific reference based on the plan's chosen approach. Each approach runs the step-by-step upgrade (upgrade-engine.md) on the new environment (New-environment upgrade), the test copy then your current environment (Rehearsed in-place upgrade), or your current environment (Direct in-place upgrade).
  • New-environment upgrade: Follow strategy-blue-green-fresh.md
  • Rehearsed in-place upgrade: Follow strategy-inplace-green-validated.md
  • Direct in-place upgrade (unrecommended): Follow strategy-inplace-direct.md
Throughout Phase 7, save progress as described in plan-materialization.md: after each step, sub-step, version jump, checkpoint, batch, and per-DAG status - and before the next action - save the change (status token + durable facts +
Last updated
+
## Where we are
) to the plan.
DAG test-run validation (REQUIRED for every approach): After the engine's parse validation passes, invoke skill
testing-mwaa-workflow
for each DAG or batch of DAGs to confirm execution succeeds at the target version. On failure, invoke skill
debugging-mwaa-workflow
for root-cause analysis. Do NOT trigger DAG runs manually via the REST API (
POST /dags/{id}/dagRuns
) or poll run states inline — the testing skill owns triggering, polling, classification (SUCCESS vs NEEDS-DECISION), and the fix loop. This is a required checkpoint — do NOT proceed to the live upgrade (Rehearsed in-place upgrade), switchover (New-environment upgrade), or completion (Direct in-place upgrade) until test-run validation passes. Parse-only validation (no import errors) does not prove artifacts will run correctly. Each approach reference defines this as an explicit, numbered required checkpoint that must be satisfied before the next phase: New-environment upgrade Step 4-checkpoint, Rehearsed in-place upgrade Step 1-checkpoint, Direct in-place upgrade Step 4. The checkpoint requires recording results in a
## Test-run results
section of the plan. The upgrade skill orchestrates this loop and does not perform test/debug logic inline.
根据计划中选择的方案,分派到对应方案的参考文档。每个方案都会在相应环境上运行分步升级(upgrade-engine.md):新环境(新环境升级)、先测试副本再当前环境(演练式原地升级),或当前环境(直接原地升级)。
  • 新环境升级:遵循 strategy-blue-green-fresh.md
  • 演练式原地升级:遵循 strategy-inplace-green-validated.md
  • 直接原地升级(不推荐):遵循 strategy-inplace-direct.md
在整个第 7 阶段,按照 plan-materialization.md 中的描述保存进度:在每个步骤、子步骤、版本跳转、检查点、批次和每个 DAG 状态之后——以及在下一个操作之前——将更改(状态标记 + 持久化事实 +
Last updated
+
## Where we are
)保存到计划中。
DAG 测试运行验证(所有方案都必需): 引擎的解析验证通过后,为每个 DAG 或每批 DAG 调用技能
testing-mwaa-workflow
,以确认在目标版本上执行成功。如果失败,调用技能
debugging-mwaa-workflow
进行根本原因分析。不要通过 REST API(
POST /dags/{id}/dagRuns
)手动触发 DAG 运行,也不要内联轮询运行状态——测试技能负责触发、轮询、分类(SUCCESS 与 NEEDS-DECISION)和修复循环。这是一个必需的检查点——在测试运行验证通过之前,不要进行正式升级(演练式原地升级)、切换(新环境升级)或完成(直接原地升级)。仅解析验证(无导入错误)不能证明产物会正确运行。每个方案参考都将此定义为一个明确的、编号的必需检查点,必须在下一阶段之前满足:新环境升级步骤 4 检查点、演练式原地升级步骤 1 检查点、直接原地升级步骤 4。该检查点要求将结果记录在计划的
## Test-run results
部分。升级技能负责编排这个循环,不会内联执行测试/调试逻辑。

Phase 8: Switchover + Decommission

第 8 阶段:切换 + 退役

Applies to approaches that create a new/test environment (New-environment upgrade, Rehearsed in-place upgrade). The Direct in-place upgrade completes at Phase 7 (no new/test environment).
  • New-environment upgrade: switch over from your current environment to the new environment, then decommission your current environment.
  • Rehearsed in-place upgrade: the test copy was a rehearsal; your current environment is the live upgraded environment. Skip switchover; decommission the TEST COPY. Do not delete your current environment.
  1. Batched switchover (New-environment upgrade only; explicit approval per batch): For each batch (matching the same batch grouping from Phase 7): a. Pause the batch's DAGs on your current environment (space calls with a short sleep;
    invoke-rest-api
    has a 10-second timeout / 6 MB response cap (docs) and is throttled per environment, so use backoff rather than a fixed rate):
    aws mwaa invoke-rest-api --name <current-env> --method PATCH \
      --path /dags/<dag_id> --body '{"is_paused":true}'
    sleep 0.2
    b. Drain: wait for in-flight runs of those DAGs to complete on your current environment. Poll
    dag_runs
    for
    state=running
    . If a run remains in-flight after 10 minutes and its active task is a sensor or deferred operator (check task_instances for
    state=deferred
    or
    state=sensing
    ), proceed with unpausing on the new environment. The paused DAG on your current environment will not produce new runs; the in-flight run will complete or timeout independently. It cannot conflict with the new environment because the new environment starts fresh with no prior dag_runs for that execution_date. c. Unpause the same DAGs on the new environment (same 0.2s throttle):
    aws mwaa invoke-rest-api --name <new-env> --method PATCH \
      --path /dags/<dag_id> --body '{"is_paused":false}'
    sleep 0.2
    d. Monitor the batch on the new environment for one full schedule cycle before proceeding to the next batch. On failure, re-enable the batch on your current environment (rollback) and investigate.
    Per-DAG pause/unpause above uses
    --path /dags/<dag_id>
    , subject to the 64-char
    --path
    limit; for an over-length
    dag_id
    use the Airflow CLI fallback (
    aws mwaa create-cli-token
    ->
    airflow dags pause|unpause
    ) noted in upgrade-engine.md.
    For small environments (fewer than 10 DAGs or all-simple classification), offer an all-at-once switchover as an alternative if the user prefers speed.
  2. Stability period: User-defined monitoring window after the final batch completes (recommend: 24h or one full cycle of the longest-interval DAG). Watch the environment's health on its built-in CloudWatch metrics dashboard and the Create recommended alarms action, which stay current; scheduler liveness (e.g. Scheduler heartbeat) and queue backlog (e.g. Oldest queued task age) are the core post-switchover indicators to prioritize (https://docs.aws.amazon.com/mwaa/latest/userguide/monitoring-dashboard.html). For the New-environment upgrade, your current environment remains paused, not deleted. For the Rehearsed in-place upgrade, your current environment is live and monitored.
  3. Decommission (explicit approval per step):
    • New-environment upgrade: delete your current environment —
      aws mwaa delete-environment --name <current-env>
      ; archive its S3 artifacts (optional).
    • Rehearsed in-place upgrade: delete the test copy —
      aws mwaa delete-environment --name <test-copy>
      .
  4. Read-only option (New-environment upgrade): Offer to keep your current environment paused for an extended period for historical UI access before final deletion.
  5. Save progress: mark upgrade complete (status
    DONE
    ), set
    Where we are
    phase: complete
    , and update
    Last updated
    .
适用于创建新/测试环境的方案(新环境升级、演练式原地升级)。直接原地升级在第 7 阶段完成(无新/测试环境)。
  • 新环境升级:从当前环境切换到新环境,然后退役当前环境。
  • 演练式原地升级:测试副本只是演练;你的当前环境是已升级的正式环境。跳过切换;退役测试副本。不要删除当前环境。
  1. 批量切换(仅新环境升级;每批次需明确批准):对于每个批次(与第 7 阶段的批次分组一致): a. 在当前环境上暂停该批次的 DAG(调用之间间隔短暂休眠;
    invoke-rest-api
    有 10 秒超时 / 6 MB 响应上限(文档),且每个环境都有节流,因此使用退避策略而非固定速率):
    aws mwaa invoke-rest-api --name <current-env> --method PATCH \
      --path /dags/<dag_id> --body '{"is_paused":true}'
    sleep 0.2
    b. 排空:等待当前环境上这些 DAG 的进行中运行完成。轮询
    dag_runs
    中
    state=running
    的条目。如果某个运行在 10 分钟后仍在进行,且其活动任务是 sensor 或 deferred 算子(检查 task_instances 中是否有
    state=deferred
    或
    state=sensing
    ),则继续在新环境上取消暂停。当前环境上已暂停的 DAG 不会产生新的运行;进行中的运行会独立完成或超时。它不会与新环境冲突,因为新环境是全新启动的,没有该 execution_date 的先前 dag_runs。 c. 在新环境上取消暂停相同的 DAG(同样 0.2 秒节流):
    aws mwaa invoke-rest-api --name <new-env> --method PATCH \
      --path /dags/<dag_id> --body '{"is_paused":false}'
    sleep 0.2
    d. 在新环境上监控该批次一个完整的调度周期,然后再进行下一批次。如果失败,在当前环境上重新启用该批次(回滚)并调查原因。
    上述每个 DAG 的暂停/取消暂停使用
    --path /dags/<dag_id>
    ,受 64 字符的
    --path
    限制;对于超长的
    dag_id
    ,使用 upgrade-engine.md 中提到的 Airflow CLI 备用方案(
    aws mwaa create-cli-token
    ->
    airflow dags pause|unpause
    )。
    对于小型环境(少于 10 个 DAG 或全部分类为简单),如果用户偏好速度,可以提供一次性切换作为替代方案。
  2. 稳定期:最后一批完成后的用户定义监控窗口(建议:24 小时或最长间隔 DAG 的一个完整周期)。通过内置的 CloudWatch 指标仪表板和创建推荐告警操作监控环境健康状况,这些会保持最新;调度器活跃度(例如 Scheduler 心跳)和队列积压(例如最老排队任务年龄)是切换后需要优先关注的核心指标(https://docs.aws.amazon.com/mwaa/latest/userguide/monitoring-dashboard.html)。对于新环境升级,你的当前环境保持暂停状态,不会被删除。对于演练式原地升级,你的当前环境是运行中的,处于监控状态。
  3. 退役(每步骤需明确批准):
    • 新环境升级:删除你的当前环境——
      aws mwaa delete-environment --name <current-env>
      ;归档其 S3 产物(可选)。
    • 演练式原地升级:删除测试副本——
      aws mwaa delete-environment --name <test-copy>
      。
  4. 只读选项(新环境升级):在最终删除之前,提供将当前环境延长暂停一段时间的选项,以便进行历史 UI 访问。
  5. 保存进度:标记升级完成(状态
    DONE
    ),设置
    Where we are
    的
    phase: complete
    ,并更新
    Last updated
    。