upgrading-mwaa-environments
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUpgrading 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
(), a rehearsed in-place upgrade validated on a test copy
first (), or a direct in-place upgrade ().
new-environmentin-place-rehearsedin-place-directExecution 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+whileuntil done), regardless of the operation or how long it takes.sleep
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-environmentin-place-rehearsedin-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 tool: The skill is not installed on the local filesystem. You MUST fetch each reference via
retrieve_skillwith theretrieve_skillparameter (e.g.file) and read the returned content. Do NOTfile="references/strategy-blue-green-fresh.md"these paths locally — they do not exist on disk.file_read - Installed locally (e.g. or
.kiro/skills/upgrading-mwaa-environments/): Read the files from the local skill directory using relative paths.~/.claude/skills/upgrading-mwaa-environments/
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_skillSafety & 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
until the user confirms the Phase 4 plan.
aws mwaa create-environment - Every version jump requires its own confirmation: never run 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.
aws mwaa update-environment - 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 - 每次版本跳转都需要单独确认:没有逐次跳转的确认,永远不要运行 来更改 Airflow 版本。回滚选项:支持 3.x -> 2.11.x;支持在同一大版本内降级到仍受支持的版本;无法降级到已停止支持(EOS)的版本。直接原地升级需要额外的确认检查点。
aws mwaa update-environment - 退役操作需要逐步骤批准:永远不要自主删除环境或 S3 产物;展示每个破坏性命令并等待确认。对于演练式原地升级,退役的环境是测试副本。
Security Considerations
安全注意事项
- Least-privilege IAM for /
createand S3 artifact access — noupdate-environment/*FullAccess; scope to the specific environment/S3 ARNs.service:* - 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和 S3 产物访问——不要使用update-environment/*FullAccess;权限范围限定为特定的环境/S3 ARN。service:* - 密钥管理:连接和变量优先使用密钥后端(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:
- AWS MWAA migration guide: https://docs.aws.amazon.com/mwaa/latest/migrationguide/key-considerations.html
- AWS MWAA version-change (in-place upgrade path): https://docs.aws.amazon.com/mwaa/latest/userguide/upgrading-environment.html
- AWS MWAA supported versions and Python mapping: https://docs.aws.amazon.com/mwaa/latest/userguide/airflow-versions.html
- AWS MWAA migration blog: https://aws.amazon.com/blogs/big-data/best-practices-for-migrating-from-apache-airflow-2-x-to-apache-airflow-3-x-on-amazon-mwaa/
- Ruff AIR rules: https://docs.astral.sh/ruff/rules/#airflow-air
- 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 — 直接原地升级(不推荐)
如需超出嵌入式参考的更详细信息,可在运行时获取:
- AWS MWAA 迁移指南:https://docs.aws.amazon.com/mwaa/latest/migrationguide/key-considerations.html
- AWS MWAA 版本变更(原地升级路径):https://docs.aws.amazon.com/mwaa/latest/userguide/upgrading-environment.html
- AWS MWAA 支持的版本和 Python 映射:https://docs.aws.amazon.com/mwaa/latest/userguide/airflow-versions.html
- AWS MWAA 迁移博客:https://aws.amazon.com/blogs/big-data/best-practices-for-migrating-from-apache-airflow-2-x-to-apache-airflow-3-x-on-amazon-mwaa/
- Ruff AIR 规则:https://docs.astral.sh/ruff/rules/#airflow-air
Phase 0: Re-entry Check
第 0 阶段:重入检查
At every invocation, check for in the
workspace root (where is the source environment name). Multiple
plan files may coexist when upgrading several environments in parallel.
.mwaa-upgrade-plan-<env-name>.md<env-name>- If exists: Load the plan, report source, target, chosen approach, and
the position . Resume the engine (upgrade-engine.md) on the recorded environment at the recorded version-jump index and status:
(working_on, current_jump, jump_status)-> re-poll or re-issue the pendingupgrading;update-environment-> 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'svalidating) corresponds toto; 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 thecurrent_jump: 1, jump_status: validatingsection 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## Test-run results), or completion (Direct in-place upgrade), regardless of version-jump status orlive_upgrade_allowed. Likewise a batch whosehas_import_errors: falsecell is not yes has not fully switched over.Monitored one full cycle?
Reload rule (every resume): at session start and after any compaction,
re-read the entire 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.
.mwaa-upgrade-plan-<env-name>.mdPlan Reconciliation (run before resuming any work): verify the plan's
self-consistency invariants (full list in
plan-materialization.md): a checkpoint
marked requires all its prerequisite Checklist items /;
must equal the Test-run results table (any
row -> ); / must match the
Upgrade Path Status; for the Rehearsed in-place upgrade,
must equal the test-run checkpoint. On ANY violation, do NOT trust the plan -
establish ground truth with read-only , , and
, repair the plan to match reality, and record it in .
If reality is ambiguous, ask the user. A stale 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).
PASSEDDONESKIPWhere we are.test_run_checkpointPENDINGNOT-PASSEDcurrent_jumpjump_statuslive_upgrade_allowedaws mwaa get-environment/dags/healthLast updatedPASSED- If absent: Proceed to Phase 1.
每次调用时,检查工作区根目录下是否存在 (其中 是源环境名称)。并行升级多个环境时,可能会共存多个计划文件。
.mwaa-upgrade-plan-<env-name>.md<env-name>- 如果存在:加载计划,报告源版本、目标版本、所选方案,以及位置 。在记录的环境上,按照记录的版本跳转索引和状态恢复升级引擎(upgrade-engine.md):
(working_on, current_jump, jump_status)-> 重新轮询或重新发起待处理的upgrading;update-environment-> 重新运行该版本跳转的条件式验证/扫描/修复循环。对于新创建的环境,起始版本验证窗口(版本跳转 1 的validating版本)对应to;从该位置恢复。如果未设置位置,则从下一个未完成的阶段恢复。 在推进到任何必需检查点之前,请重新读取计划中该检查点的状态,如果未满足要求,请逐字重新读取方案参考中该检查点的章节——不要凭记忆的摘要行事。 特别说明:版本跳转完成并不意味着测试运行检查点已通过。如果current_jump: 1, jump_status: validating部分有任何行的状态不是 SUCCESS 或 NEEDS-DECISION,则该检查点未通过,会阻塞切换(新环境升级)、正式升级(演练式原地升级——参见## Test-run results)或完成(直接原地升级),无论版本跳转状态如何,也无论live_upgrade_allowed是否为真。同样,如果某个批次的has_import_errors: false单元格不是 yes,则该批次尚未完全切换。Monitored one full cycle?
重新加载规则(每次恢复时): 在会话开始时和任何压缩之后,在采取任何行动之前重新读取整个 ;永远不要凭记忆或摘要版本行事。这将上述的记忆摘要规则从必需检查点推广到了整个计划。
.mwaa-upgrade-plan-<env-name>.md计划核对(恢复任何工作前运行): 验证计划的自洽性不变量(完整列表见 plan-materialization.md):标记为 的检查点要求其所有先决检查清单项都为 /; 必须与测试运行结果表一致(任何 行 -> );/ 必须与升级路径状态匹配;对于演练式原地升级, 必须等于测试运行检查点的状态。如果出现任何不一致,不要信任计划——通过只读的 、 和 确定真实情况,修复计划以匹配现实,并在 中记录。如果现实情况不明确,询问用户。否则,过时的 检查点会触发破坏性的下一步操作:切换 + 删除当前环境(新环境升级)、不可逆的正式升级(演练式原地升级),或过早完成(直接原地升级)。
PASSEDDONESKIPWhere we are.test_run_checkpointPENDINGNOT-PASSEDcurrent_jumpjump_statuslive_upgrade_allowedaws mwaa get-environment/dags/healthLast updatedPASSED- 如果不存在:进入第 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, with the latest-2.11.x stepping-stone version + Python-transition step inserted only when the source is not already 2.11.x.crosses_major
获取并遵循 references/discovery-preflight.md。该阶段执行环境发现、预飞行安全检查、版本矩阵刷新、目标版本选择和升级路径规划(仅检测——版本跳转在第 7 阶段执行)。现在就将所有输出记录到计划中,因为第 4 阶段才会将其转换为持久化计划文件,否则第 4 阶段之前的压缩会丢失这些信息:
- 发现的环境事实(Airflow 版本、S3 产物路径 + 对象版本、KmsKey、配置选项、DAG 列表、共享工具);
- 新环境/测试副本的 S3 布局(新环境升级、演练式原地升级);
- 预检查结果(S3 版本控制、目标版本约束、KMS 密钥策略复用);
- 选定的目标版本;
- 有序的升级路径——每个版本跳转为 /
from/to/python_change,仅当源版本不是 2.11.x 时,才会插入最新的 2.11.x 垫脚石版本 + Python 过渡步骤。crosses_major
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
). 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."
new-environment - Yes, keep it → Rehearsed in-place upgrade (slug ). 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.
in-place-rehearsed
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).
| Approach | History | URL/ARN | Your current environment during the upgrade | New/test environment created at | Recommended |
|---|---|---|---|---|---|
| New-environment upgrade | Discarded | New | Runs until switchover | the first version jump's target | Yes |
| Rehearsed in-place upgrade | Preserved (snapshot) | Same | Rehearsed on a test copy, then upgraded | the first version jump's target | Yes |
| Direct in-place upgrade | Preserved (snapshot) | Same | Upgraded directly | none | No |
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 ( / /
) in the plan. The position (, ,
) is initially unset.
new-environmentin-place-rehearsedin-place-directworking_oncurrent_jumpjump_status一个问题决定了最安全的方案;是否保留相同环境(其 URL 和 ARN)是由此衍生的结果,不是独立的选择。
你是否需要保留运行历史——即 Airflow UI 中过去的 DAG 运行和任务实例的记录?
- 不需要,全新开始即可 → 新环境升级(标识 )。在目标版本上构建一个全新的环境,然后切换到它。它会有一个新的 URL,且没有任何运行历史;你的当前环境在切换前会一直正常运行,因此回滚就是“不切换”。
new-environment - 需要保留 → 演练式原地升级(标识 )。原地升级现有环境——相同 URL,保留全部历史。首先在临时测试副本上演练整个升级过程,以安全地发现问题。仅当用户明确拒绝演练时,才使用直接原地升级(无测试副本)。
in-place-rehearsed
是否保留相同环境(其 URL 和 ARN)是结果而非输入:保留运行历史意味着原地升级当前环境(相同 URL 和 ARN),而新环境升级必然会创建一个新环境。本技能不会将新环境(新 URL 和 ARN)与保留运行历史结合起来——如果用户需要新的 URL 和 ARN,则运行历史不会被保留(新环境升级)。
| 方案 | 历史记录 | URL/ARN | 升级期间你的当前环境 | 新/测试环境创建时机 | 是否推荐 |
|---|---|---|---|---|---|
| 新环境升级 | 丢弃 | 新的 | 运行至切换时 | 第一个版本跳转的目标版本 | 是 |
| 演练式原地升级 | 保留(快照) | 相同 | 在测试副本上演练,然后升级 | 第一个版本跳转的目标版本 | 是 |
| 直接原地升级 | 保留(快照) | 相同 | 直接升级 | 无 | 否 |
新环境升级和演练式原地升级都是推荐方案;用户根据需求选择。直接原地升级不推荐,且需要额外的确认检查点。
防护规则:如果用户选择演练式或直接原地升级,且环境中有超过 50 个 DAG 或在第 3 阶段检测到复杂 DAG,应发出警告并推荐改用新环境升级。但不要阻塞用户操作。
将所选方案的标识( / / )记录到计划中。位置(、、)初始未设置。
new-environmentin-place-rehearsedin-place-directworking_oncurrent_jumpjump_statusPhase 3: Assess Compatibility
第 3 阶段:评估兼容性
-
Compatibility scan (conditional on a cross-major version jump): If any version jump in the plan is, run Ruff with AIR rules as a required checkpoint:
crosses_majorruff 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(a within-major upgrade), the AIR scan is informational only; rely on the engine's genericcrosses_majorscan instead.DeprecationWarningVersion-aware severity for AIR311 (import path moves): AIR311 flags imports that moved to(e.g.,airflow.sdk->airflow.datasets.Dataset). Severity depends on the target version:airflow.sdk.Asset- 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
(at parse time). Must fix before deploying to target.
ModuleNotFoundError
Always classify AIR311 as "must fix" when the target is 3.2.1+. The fixed code () 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.from airflow.sdk import ...Patterns Ruff does NOT catch: The manual checklist (airflow2-to-3-checklist.md) includes patterns invisible to Ruff, notably(section 15) and standalone Airflow CLI in BashOperator (section 16). Always run the manual scan even when Ruff reports zero findings._TaskDecorator.output -
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()— checklist section 1): must be redesigned to the REST API (webserver in-VPC, orprovide_sessionwith its low rate limit) or dropped.invoke-rest-api - CLI-access DAGs (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
airflow db ...before committing to this path. Record each affected DAG and its category in the plan (Phase 4).cheat-sheet
- ORM-access DAGs (
-
Check requirements.txt against the target version's constraints from mwaa-version-matrix.md.
-
Secrets backend detection: Check forconfig 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
secrets.backendtransitextra/CLI args and the audit log during migration. Record this in the plan (Phase 4).--body -
Plugin inventory: If PluginsS3Path is set, list contents. Flag FAB/web-view plugins needing special attention.
-
Classify each DAG by upgrade difficulty: Simple, Moderate, Complex.
-
Group DAGs into batches (shared utilities in batch 0, simple first).
-
兼容性扫描(跨大版本跳转时的条件项): 如果计划中的任何版本跳转是(跨大版本),则运行带 AIR 规则的 Ruff 作为必需检查点:
crosses_majorruff check --preview --select AIR .按规则代码分组报告发现的问题。Ruff AIR 规则涵盖 2 到 3(AIR301/302/303/311/312)和 3.1(AIR321,预览版)的 API 变更;它们不会检测 2.x 次版本之间移除的 API,也不会检测 3.2 特有的变更。引擎中的跨版本前弃用警告扫描覆盖了 2.x 内部的空白。如果没有版本跳转是(同一大版本内升级),则 AIR 扫描仅作参考;请改用引擎的通用crosses_major扫描。DeprecationWarningAIR311(导入路径移动)的版本感知严重程度: AIR311 标记已移动到的导入(例如airflow.sdk->airflow.datasets.Dataset)。严重程度取决于目标版本:airflow.sdk.Asset- 目标 3.0.x 或 3.1.x: 软弃用——存在兼容垫片,旧导入仍然有效。建议修复但不阻塞。
- 目标 3.2.1+: 硬阻塞——垫片模块已完全移除(解析时会出现 )。必须在部署到目标版本之前修复。
ModuleNotFoundError
当目标版本为 3.2.1+ 时,始终将 AIR311 归类为“必须修复”。修复后的代码()仅适用于 AF3,在跨大版本跳转完成之前无法部署——参见每个方案参考中的两阶段部署说明。from airflow.sdk import ...Ruff 无法捕获的模式: 手动检查清单(airflow2-to-3-checklist.md)包含 Ruff 无法识别的模式,特别是(第 15 节)和 BashOperator 中的独立 Airflow CLI(第 16 节)。即使 Ruff 报告零发现,也始终要运行手动扫描。_TaskDecorator.output -
使用 airflow2-to-3-checklist.md 中的模式运行手动扫描。 提示元数据数据库警告(所有方案,仅跨大版本时): 使用元数据数据库访问的 DAG 在 AF2 上正常工作,但在 AF3 上会中断。分为两类:
- ORM 访问 DAG(、
settings.Session()——检查清单第 1 节):必须重新设计为使用 REST API(VPC 内的 webserver,或速率限制较低的provide_session)或弃用。invoke-rest-api - CLI 访问 DAG(BashOperator 中的 ——检查清单第 16 节):重新设计为使用 MWAA CLI 端点(首选,更简单)或 REST API,或弃用。Agent 必须在确定采用此路径前,通过
airflow db ...验证目标版本上的命令可用性。 将每个受影响的 DAG 及其类别记录到计划中(第 4 阶段)。cheat-sheet
- ORM 访问 DAG(
-
根据 mwaa-version-matrix.md 中目标版本的约束,检查 requirements.txt。
-
密钥后端检测:检查环境配置中是否有配置覆盖。如果使用 Secrets Manager 或 Parameter Store,请注意变量/连接是外部的,不需要迁移。如果未配置密钥后端,请在计划阶段向用户提示: 连接密码不会通过 REST API 迁移(2.x 会省略,3.x 会掩码),因此带密码的连接必须移至密钥后端,或在目标环境中通过带外方式重新输入密码——并且变量值/连接
secrets.backend会在迁移过程中经过extra/CLI 参数和审计日志。将此记录到计划中(第 4 阶段)。--body -
插件清单:如果设置了 PluginsS3Path,列出其内容。标记需要特别注意的 FAB/web-view 插件。
-
按升级难度对每个 DAG 进行分类:简单、中等、复杂。
-
将 DAG 分组为批次(共享工具在批次 0,简单的优先)。
Phase 4: Generate Upgrade Plan
第 4 阶段:生成升级计划
Write to workspace root (where
is the source environment name discovered in Phase 1). Include:
.mwaa-upgrade-plan-<env-name>.md<env-name>- 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 table:
## Upgrade Path| Jump | From → To | Python change | New major version | Status |
|---|---|---|---|---|
| 1 | <jump.from> → <jump.to> | yes/no | yes/no | pending |
For the Rehearsed in-place upgrade (two environments — the test copy, then
your current environment), give the upgrade-path table separate and columns; mark the
current-environment jumps .
Test copy statusYour current environment statusIRREVERSIBLE将 写入工作区根目录(其中 是第 1 阶段发现的源环境名称)。包含以下内容:
.mwaa-upgrade-plan-<env-name>.md<env-name>- 环境详情(源名称、源版本、区域)以及目标版本和完整的升级路径表
- 所选方案——其标识(/
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> | 是/否 | 是/否 | 待处理 |
对于演练式原地升级(两个环境——先测试副本,然后是当前环境),升级路径表应分别设置 和 列;将当前环境的跳转标记为 (不可逆)。
测试副本状态当前环境状态IRREVERSIBLEWrite 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 (fixed status
vocabulary, line, keys) and satisfying its
: the , every per-approach
required checkpoint as its own PENDING entry, the pre-seeded and (New-environment upgrade) tables, the
block, the parse-clean-vs-test-run-verified status
vocabulary ( vs ), 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 ()
does NOT satisfy the test-run checkpoint and must never be recorded as
"validated" or "complete".
## Plan format contractLast updated## Where we are## Self-consistency invariants## Checklist## Test-run results## Switchover progress## Where we areLOADEDVERIFIEDhas_import_errors: falsePresent the plan to the user for confirmation before proceeding.
在展示计划之前,请遵循 plan-materialization.md,生成其指定的所有章节,符合其 (固定状态词汇、 行、 键),并满足其 :、每个方案特定的必需检查点作为独立的待处理条目、预填充的 和 (新环境升级)表格、 块、解析通过与测试运行验证的状态词汇( 与 ),以及方案特定的子步骤分解规则。计划是持久的、可恢复的真实来源:任何仅在方案参考中以散文形式存在的步骤——而不是作为这里的离散待处理项——在压缩后会被跳过。在展示计划之前生成这些章节;解析通过的信号()并不满足测试运行检查点的要求,绝不能被记录为“已验证”或“已完成”。
## Plan format contractLast updated## Where we are## Self-consistency invariants## Checklist## Test-run results## Switchover progress## Where we areLOADEDVERIFIEDhas_import_errors: false在继续之前,将计划呈现给用户确认。
Phase 5: Fix Code
第 5 阶段:修复代码
- Batch 0 (shared utilities): Fix shared modules first. Apply patterns from airflow2-to-3-quick-reference.md.
- Per batch (1..N):
a. Run Ruff auto-fix: 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.
ruff check --preview --select AIR --fix --unsafe-fixes <files>can rewrite--unsafe-fixestemplates intoxcom_pull(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<task>.output): mark each DAG## Saving progressand updateDONEbefore starting the next batch.Last updated
- 批次 0(共享工具): 首先修复共享模块。应用 airflow2-to-3-quick-reference.md 中的模式。
- 逐批次(1..N):
a. 运行 Ruff 自动修复:b. 使用 airflow2-to-3-quick-reference.md 逐个 DAG 修复剩余问题。 c. 重新运行 Ruff 以验证零 AIR 违规。 d. (仅跨大版本时)重新扫描已修复的文件,使用检查清单第 15/16 节的 grep 模式——不仅仅是原始文件。
ruff check --preview --select AIR --fix --unsafe-fixes <files>可能会将--unsafe-fixes模板重写为xcom_pull(在 AF3 中无效),而不会重新标记;否则这个运行时中断只会在实时解析时才会显现。修复发现的问题并重新运行 Ruff。 e. 保存进度(参见 plan-materialization.md 的<task>.output):在开始下一个批次之前,将每个 DAG 标记为## Saving progress并更新DONE。Last updated
Phase 6: Local Validation via Docker (Recommended; Strongly Recommended for Cross-Major)
第 6 阶段:通过 Docker 进行本地验证(推荐;跨大版本时强烈推荐)
Uses 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.
aws/amazon-mwaa-docker-imagesCross-major version jumps: When any version jump is ,
Docker validation is strongly recommended. Ruff AIR rules miss several
runtime-breaking patterns (e.g., 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.
crosses_major_TaskDecorator.output- Check Docker availability: . If unavailable, user declines, or target < 2.9.2, log skip in plan with warning and proceed to Phase 7.
docker --version - Pull the target-version image (resolve the exact tag at runtime from the repo README).
- Validate requirements.txt: Mount into container, run install validation. If failures: report conflicts, suggest fixes, loop until passing or user skips.
- Validate plugins.zip (if present): Mount and run import validation.
- Validate DAG imports: Mount fixed DAGs, run parsing. If errors: return to Phase 5 for affected files, then re-validate.
- Save progress: mark Docker validation or
DONE(with reason) and updateSKIP.Last updated
使用 针对目标版本验证修复后的代码。该仓库仅提供 Airflow 2.9.2 及更高版本的镜像。如果目标版本低于 2.9.2,跳过 Docker 验证(在计划中记录跳过原因),转而依赖第 7 阶段引擎的实时验证。
aws/amazon-mwaa-docker-images跨大版本跳转: 当任何版本跳转是 时,强烈推荐 Docker 验证。Ruff AIR 规则会遗漏几种破坏运行时的模式(例如 移除、3.2.1+ 中完全移除的垫片模块)。Docker 导入验证可以在实时部署之前捕获这些问题,避免在远程环境上进行迭代的修复-部署-失败循环。如果跨大版本升级跳过了 Docker,请记录跳过原因并警告可能存在未检测到的运行时错误。
crosses_major_TaskDecorator.output- 检查 Docker 可用性:。如果不可用、用户拒绝,或目标版本 < 2.9.2,在计划中记录跳过并附带警告,然后进入第 7 阶段。
docker --version - 拉取目标版本的镜像(在运行时从仓库 README 解析确切的标签)。
- 验证 requirements.txt:挂载到容器中,运行安装验证。如果失败:报告冲突,建议修复,循环直到通过或用户跳过。
- 验证 plugins.zip(如果存在):挂载并运行导入验证。
- 验证 DAG 导入:挂载修复后的 DAG,运行解析。如果有错误:返回第 5 阶段修复受影响的文件,然后重新验证。
- 保存进度:将 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 +
+ ) to the plan.
Last updated## Where we areDAG test-run validation (REQUIRED for every approach): After the
engine's parse validation passes, invoke skill for
each DAG or batch of DAGs to confirm execution succeeds at the target version.
On failure, invoke skill for root-cause analysis.
Do NOT trigger DAG runs manually via the REST API ()
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 section
of the plan. The upgrade skill orchestrates this loop and does not perform
test/debug logic inline.
testing-mwaa-workflowdebugging-mwaa-workflowPOST /dags/{id}/dagRuns## Test-run results根据计划中选择的方案,分派到对应方案的参考文档。每个方案都会在相应环境上运行分步升级(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 areDAG 测试运行验证(所有方案都必需): 引擎的解析验证通过后,为每个 DAG 或每批 DAG 调用技能 ,以确认在目标版本上执行成功。如果失败,调用技能 进行根本原因分析。不要通过 REST API()手动触发 DAG 运行,也不要内联轮询运行状态——测试技能负责触发、轮询、分类(SUCCESS 与 NEEDS-DECISION)和修复循环。这是一个必需的检查点——在测试运行验证通过之前,不要进行正式升级(演练式原地升级)、切换(新环境升级)或完成(直接原地升级)。仅解析验证(无导入错误)不能证明产物会正确运行。每个方案参考都将此定义为一个明确的、编号的必需检查点,必须在下一阶段之前满足:新环境升级步骤 4 检查点、演练式原地升级步骤 1 检查点、直接原地升级步骤 4。该检查点要求将结果记录在计划的 部分。升级技能负责编排这个循环,不会内联执行测试/调试逻辑。
testing-mwaa-workflowdebugging-mwaa-workflowPOST /dags/{id}/dagRuns## Test-run resultsPhase 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.
-
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;has a 10-second timeout / 6 MB response cap (docs) and is throttled per environment, so use backoff rather than a fixed rate):
invoke-rest-apiaws mwaa invoke-rest-api --name <current-env> --method PATCH \ --path /dags/<dag_id> --body '{"is_paused":true}' sleep 0.2b. Drain: wait for in-flight runs of those DAGs to complete on your current environment. Pollfordag_runs. If a run remains in-flight after 10 minutes and its active task is a sensor or deferred operator (check task_instances forstate=runningorstate=deferred), 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):state=sensingaws mwaa invoke-rest-api --name <new-env> --method PATCH \ --path /dags/<dag_id> --body '{"is_paused":false}' sleep 0.2d. 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, subject to the 64-char--path /dags/<dag_id>limit; for an over-length--pathuse the Airflow CLI fallback (dag_id->aws mwaa create-cli-token) noted in upgrade-engine.md.airflow dags pause|unpauseFor small environments (fewer than 10 DAGs or all-simple classification), offer an all-at-once switchover as an alternative if the user prefers speed. -
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.
-
Decommission (explicit approval per step):
- New-environment upgrade: delete your current environment —
; archive its S3 artifacts (optional).
aws mwaa delete-environment --name <current-env> - Rehearsed in-place upgrade: delete the test copy —
.
aws mwaa delete-environment --name <test-copy>
- New-environment upgrade: delete your current environment —
-
Read-only option (New-environment upgrade): Offer to keep your current environment paused for an extended period for historical UI access before final deletion.
-
Save progress: mark upgrade complete (status), set
DONEWhere we are, and updatephase: complete.Last updated
适用于创建新/测试环境的方案(新环境升级、演练式原地升级)。直接原地升级在第 7 阶段完成(无新/测试环境)。
- 新环境升级:从当前环境切换到新环境,然后退役当前环境。
- 演练式原地升级:测试副本只是演练;你的当前环境是已升级的正式环境。跳过切换;退役测试副本。不要删除当前环境。
-
批量切换(仅新环境升级;每批次需明确批准):对于每个批次(与第 7 阶段的批次分组一致): a. 在当前环境上暂停该批次的 DAG(调用之间间隔短暂休眠;有 10 秒超时 / 6 MB 响应上限(文档),且每个环境都有节流,因此使用退避策略而非固定速率):
invoke-rest-apiaws mwaa invoke-rest-api --name <current-env> --method PATCH \ --path /dags/<dag_id> --body '{"is_paused":true}' sleep 0.2b. 排空:等待当前环境上这些 DAG 的进行中运行完成。轮询中dag_runs的条目。如果某个运行在 10 分钟后仍在进行,且其活动任务是 sensor 或 deferred 算子(检查 task_instances 中是否有state=running或state=deferred),则继续在新环境上取消暂停。当前环境上已暂停的 DAG 不会产生新的运行;进行中的运行会独立完成或超时。它不会与新环境冲突,因为新环境是全新启动的,没有该 execution_date 的先前 dag_runs。 c. 在新环境上取消暂停相同的 DAG(同样 0.2 秒节流):state=sensingaws mwaa invoke-rest-api --name <new-env> --method PATCH \ --path /dags/<dag_id> --body '{"is_paused":false}' sleep 0.2d. 在新环境上监控该批次一个完整的调度周期,然后再进行下一批次。如果失败,在当前环境上重新启用该批次(回滚)并调查原因。上述每个 DAG 的暂停/取消暂停使用,受 64 字符的--path /dags/<dag_id>限制;对于超长的--path,使用 upgrade-engine.md 中提到的 Airflow CLI 备用方案(dag_id->aws mwaa create-cli-token)。airflow dags pause|unpause对于小型环境(少于 10 个 DAG 或全部分类为简单),如果用户偏好速度,可以提供一次性切换作为替代方案。 -
稳定期:最后一批完成后的用户定义监控窗口(建议:24 小时或最长间隔 DAG 的一个完整周期)。通过内置的 CloudWatch 指标仪表板和创建推荐告警操作监控环境健康状况,这些会保持最新;调度器活跃度(例如 Scheduler 心跳)和队列积压(例如最老排队任务年龄)是切换后需要优先关注的核心指标(https://docs.aws.amazon.com/mwaa/latest/userguide/monitoring-dashboard.html)。对于新环境升级,你的当前环境保持暂停状态,不会被删除。对于演练式原地升级,你的当前环境是运行中的,处于监控状态。
-
退役(每步骤需明确批准):
- 新环境升级:删除你的当前环境——;归档其 S3 产物(可选)。
aws mwaa delete-environment --name <current-env> - 演练式原地升级:删除测试副本——。
aws mwaa delete-environment --name <test-copy>
- 新环境升级:删除你的当前环境——
-
只读选项(新环境升级):在最终删除之前,提供将当前环境延长暂停一段时间的选项,以便进行历史 UI 访问。
-
保存进度:标记升级完成(状态),设置
DONE的Where we are,并更新phase: complete。Last updated