

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 创建 Amazon MWAA 环境
<a name="create-environment"></a>

Amazon Managed Workflows for Apache Airflow 使用与 Apache 相同的开源 Apache Airflow 和用户界面，在您所选版本的环境中设置 Apache Airflow。本指南介绍创建 Amazon MWAA 环境的步骤。

**Contents**
+ [开始前的准备工作](#create-environment-before)
+ [Apache Airflow 版本](#create-environment-regions-aa-versions)
+ [创建环境](#create-environment-start)
  + [步骤 1：指定详细信息](#create-environment-start-details)
  + [步骤 2：配置高级设置](#create-environment-start-advanced)
  + [步骤 3：查看和创建](#create-environment-start-review)

## 开始前的准备工作
<a name="create-environment-before"></a>
+ 环境创建后，您将无法修改为环境指定的 [VPC 网络](vpc-create.md)。
+ 您需要将 Amazon S3 存储桶配置为**阻止所有公开访问**并启用**存储桶版本控制**。
+ 您需要 AWS 账户 具有[使用 Amazon MWAA 的权限](manage-access.md)，以及 AWS Identity and Access Management (IAM) 中的权限才能创建 IAM 角色。如果您为 Apache Airflow Web 服务器选择了**私有网络**访问模式，由于该模式会限制 Amazon VPC 内的 Apache Airflow 访问权限，因此您需要 IAM 中的权限才能创建 Amazon VPC 端点。

**注意**  
Amazon MWAA 会在创建过程中动态确定网络。如果您使用 IPv6 子网，Amazon MWAA 会创建与数据库和 Web 服务器的 IPv6 私有链路连接。Amazon MWAA 不支持在网络类型之间过渡，也无法将现有环境升级到。 IPv6

## Apache Airflow 版本
<a name="create-environment-regions-aa-versions"></a>

Amazon MWAA 上支持以下 Apache Airflow 版本。

**注意**  
自 2025 年 12 月 30 日起，Amazon MWAA 将终止对 Apache Airflow 版本 v2.4.3、v2.5.1 和 v2.6.3 的支持。有关更多信息，请参阅[Apache Airflow 版本支持和常见问题](airflow-versions.md#airflow-versions-support)。
从 Apache Airflow v2.2.2 开始，Amazon MWAA 支持直接在 Apache Airflow Web 服务器上安装 Python 要求、提供程序包和自定义插件。
 从 Apache Airflow v2.7.2 开始，要求文件必须包含一条 `--constraint` 语句。如果您未提供约束条件，Amazon MWAA 将为您指定一个约束条件，以确保您的要求中列出的程序包与您正在使用的 Apache Airflow 版本兼容。  
有关在需求文件中设置约束条件的更多信息，请参阅[安装 Python 依赖项](working-dags-dependencies.md#working-dags-dependencies-syntax-create)。


| Apache Airflow 版本 | Apache Airflow 发布日期 | Amazon MWAA 上市日期 | Apache Airflow 约束条件 | Python 版本 | 
| --- | --- | --- | --- | --- | 
|  [v2.11.0](https://airflow.apache.org/docs/apache-airflow/2.11.0)  |  [2025年5月20日](https://airflow.apache.org/docs/apache-airflow/2.11.0/release_notes.html#airflow-2-11-0-2022-05-20)  |  2026年1月7日  |  [v2.11.0 约束文件](https://raw.githubusercontent.com/apache/airflow/constraints-2.11.0/constraints-3.12.txt)  |  [Python 3.12](https://peps.python.org/pep-0693/)  | 
|  [v3.0.6](https://airflow.apache.org/docs/apache-airflow/3.0.6)  |  [2025 年 8 月 29 日](https://airflow.apache.org/docs/apache-airflow/3.0.6/release_notes.html#airflow-3-0-6-2025-08-29)  |  2025 年 10 月 1 日  |  [v3.0.6 约束文件](https://raw.githubusercontent.com/apache/airflow/constraints-3.0.6/constraints-3.12.txt)  |  [Python 3.12](https://peps.python.org/pep-0693/)  | 
|  [v2.10.3](https://airflow.apache.org/docs/apache-airflow/2.10.3)  |  [2024 年 11 月 4 日](https://airflow.apache.org/docs/apache-airflow/2.10.3/release_notes.html#airflow-2-10-3-2024-11-04)  |  2024 年 12 月 18 日  |  [v2.10.3 约束文件](https://raw.githubusercontent.com/apache/airflow/constraints-2.10.3/constraints-3.11.txt)  |  [Python 3.11](https://peps.python.org/pep-0664/)  | 
|  [v2.10.1](https://airflow.apache.org/docs/apache-airflow/2.10.1)  |  [2024 年 9 月 5 日](https://airflow.apache.org/docs/apache-airflow/2.10.1/release_notes.html#airflow-2-10-1-2024-09-05)  |  2024 年 9 月 26 日  |  [v2.10.1 约束文件](https://raw.githubusercontent.com/apache/airflow/constraints-2.10.1/constraints-3.11.txt)  |  [Python 3.11](https://peps.python.org/pep-0664/)  | 
|  [v2.9.2](https://airflow.apache.org/docs/apache-airflow/2.9.2)  |  [2024 年 6 月 10 日](https://airflow.apache.org/docs/apache-airflow/2.10.1/release_notes.html#airflow-2-9-2-2024-06-10)  |  2024 年 7 月 9 日  |  [v2.9.2 约束文件](https://raw.githubusercontent.com/apache/airflow/constraints-2.9.2/constraints-3.11.txt)  |  [Python 3.11](https://peps.python.org/pep-0664/)  | 
|  [v2.8.1](https://airflow.apache.org/docs/apache-airflow/2.8.1)  |  [2024 年 1 月 19 日](https://airflow.apache.org/docs/apache-airflow/2.10.1/release_notes.html#airflow-2-8-1-2024-01-19)  |  2024 年 2 月 23 日  |  [v2.8.1 约束文件](https://raw.githubusercontent.com/apache/airflow/constraints-2.8.1/constraints-3.11.txt)  |  [Python 3.11](https://peps.python.org/pep-0664/)  | 
|  [v2.7.2](https://airflow.apache.org/docs/apache-airflow/2.7.2)  |  [2023 年 10 月 12 日](https://airflow.apache.org/docs/apache-airflow/2.10.1/release_notes.html#airflow-2-7-2-2023-10-12)  |  2023 年 11 月 6 日  |  [v2.7.2 约束文件](https://raw.githubusercontent.com/apache/airflow/constraints-2.7.2/constraints-3.11.txt)  |  [Python 3.11](https://peps.python.org/pep-0664/)  | 

有关迁移自管理的 Apache Airflow 部署或迁移现有 Amazon MWAA 环境的更多信息，包括备份元数据数据库的说明，请参阅 [Amazon MWAA 迁移指南](https://docs.aws.amazon.com/mwaa/latest/migrationguide/index.html)。

## 创建环境
<a name="create-environment-start"></a>

下一节介绍创建 Amazon MWAA 环境的步骤。

### 步骤 1：指定详细信息
<a name="create-environment-start-details"></a>

**要指定环境的详细信息，请执行以下操作**

1. 打开 [Amazon MWAA 控制台](https://console.aws.amazon.com/mwaa/home/)。

1. 选择你的 AWS 区域。

1. 选择**创建环境**。

1. 在**指定详细信息**页面上，在**环境详细信息**下：

   1. 在**名称**中为您的环境输入唯一的名称。

   1. 在 **Airflow 版本**中选择 Apache Airflow 版本。
**注意**  
如果未指定任何值，则默认为最新的 Apache Airflow 版本。可用的最新版本是 Apache Airflow v3.0.6。

1. 在 **Amazon S3 的 DAG 代码**下指定以下内容：

   1. **S3 Bucket**。选择**浏览 S3** 并选择 Amazon S3 存储桶，或者输入 Amazon S3 URI。

   1. **DAGs folder**。选择**浏览 S3**，然后选择 Amazon S3 存储桶中的 `dags` 文件夹，或者输入 Amazon S3 URI。

   1. **插件文件-*可选***。选择**浏览 S3**，然后选择 Amazon S3 存储桶上的 `plugins.zip` 文件，或者输入 Amazon S3 URI。

   1. **要求文件-*可选***。选择**浏览 S3**，然后选择 Amazon S3 存储桶上的 `requirements.txt` 文件，或者输入 Amazon S3 URI。

   1. **启动脚本文件-*可选***，选择**浏览 S3**并选择 Amazon S3 存储桶上的脚本文件，或者输入 Amazon S3 URI。

1. 选择**下一步**。

### 步骤 2：配置高级设置
<a name="create-environment-start-advanced"></a>

**配置高级设置**

1. 在**配置高级设置**页面上，在**联网**下：

   1. 选择 [Amazon VPC](vpc-create.md)。

     此步骤将填充 Amazon VPC 中的两个私有子网。

1. 在 **Web 服务器访问**下，选择您首选的 [Apache Airflow 访问模式](configuring-networking.md)：

   1. **私有网络**。这限制了对 Apache Airflow UI 的访问，只有在* Amazon VPC 中*已获得 [环境的 IAM 策略](access-policies.md)访问权限的用户才能访问。您需要获得权限才能为此步骤创建 Amazon VPC 端点。
**注意**  
如果 Apache Airflow UI 只能在公司网络中访问，并且不需要访问公共存储库即可进行 Web 服务器要求安装，请选择**私有网络**选项。如果您选择此访问模式选项，则需要创建一种机制来访问 Amazon VPC 中的 Apache Airflow Web 服务器。有关更多信息，请参阅[访问 Apache Airflow Web 服务器的 VPC 端点（私有网络访问）](vpc-vpe-access.md#vpc-vpe-access-endpoints)。

   1. **公有网络**。这使获得[环境的 IAM 策略](access-policies.md)访问权限的用户可以通过互联网访问 Apache Airflow UI。

1. 在**安全组**下，选择用于保护 [Amazon VPC](vpc-create.md) 的安全组：

   1. 默认情况下，Amazon MWAA 会在 Amazon VPC 中创建一个安全组，并在**创建新安全组**中使用特定的入站和出站规则。

   1. **可选。**取消选中**创建新安全组**中的复选框可选择最多 5 个安全组。
**注意**  
现有 Amazon VPC 安全组必须配置特定的入站和出站规则，才能允许网络流量。要了解更多信息，请参阅 [Amazon MWAA 上的 VPC 安全](vpc-security.md)。

1. 在**环境类**下，选择一个[环境类](environment-class.md)。

   我们建议选择支持您的工作负载所需的最小尺寸。您可以随时更改环境类。

1. 对于**最大工作线程计数**，请指定要在环境中运行的 Apache Airflow 工作线程的最大数量。

   有关更多信息，请参阅[高性能用例示例](mwaa-autoscaling.md#mwaa-autoscaling-high-volume)。

1. 指定**最大 Web 服务器数**和**最小 Web 服务器数**，以配置 Amazon MWAA 如何在环境中扩展 Apache Airflow Web 服务器。

   有关 Web 服务器自动扩展的更多信息，请参阅 [配置 Amazon MWAA Web 服务器自动扩缩](mwaa-web-server-autoscaling.md)。

1. 在**加密**下，选择一个数据加密选项：

   1. 默认情况下，Amazon MWAA 使用 AWS拥有的密钥来加密您的数据。

   1. **可选。**选择 “**自定义加密设置（高级）**” 以选择其他 AWS KMS 密钥。如果您选择在此步骤中指定[客户管理的密钥](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk)，则必须指定 AWS KMS 密钥 ID 或 ARN。AWS KMS A@@ [mazon MWAA 不支持别名和多区域密钥](custom-keys-certs.md)。如果您在 Amazon S3 存储桶上指定了用于服务器端加密的 Amazon S3 密钥，则必须为 Amazon MWAA 环境指定相同的密钥。
**注意**  
您必须拥有该密钥的权限才能在 Amazon MWAA 控制台上选择该密钥。您还必须通过 [附加密钥政策](custom-keys-certs.md#custom-keys-certs-grant-policies-attach) 中所述的附加策略授予 Amazon MWAA 使用密钥的权限。

1. **推荐**。在 “**监控**” 下，为 Airflo **w 日志配置选择一个或多个日志类别，将 Apache Airflow 日志**发送到日志： CloudWatch 

   1. **Airflow 任务日志**。**选择要发送到 “登录日志” 级别的 Apache Airflow 任务日志 CloudWatch 的类型。**

   1. **Airflow Web 服务器日志**。**选择要发送到 “登录日志” 级别的 Apache Airflow 网络服务器日志的类型 CloudWatch 。**

   1. **Airflow 计划程序日志**。**选择要发送到 “登录日志” 级别的 Apache Airflow 调度程序日志的类型 CloudWatch 。**

   1. **Airflow 工作线程日志**。**选择要发送到 “登录日志” 级别的 Apache Airflow 工作日志 CloudWatch 的类型。**

   1. **Airflow DAG 处理日志**。**选择要发送到 “登录日志” 级别的 Apache Airflow DAG 处理日志 CloudWatch 的类型。**

1. **可选。**对于 **Airflow 配置选项**，选择**添加自定义配置选项**。

   您可以从 Apache Airflow 版本的 [Apache Airflow 配置选项](configuring-env-variables.md)的建议下拉列表中进行选择，也可以指定自定义配置选项。例如 `core.default_task_retries` : `3`。

1. **可选。**在**标签**下，选择**添加新标记**，将标签与环境相关联。例如，`Environment`：`Staging`。

1. 在**权限**下，选择一个执行角色。

   1. 默认情况下，Amazon MWAA 会在**创建新角色**中创建一个[执行角色](mwaa-create-role.md)。您必须具有创建 IAM 角色的权限，才能使用此选项。

   1. **可选。**选择**输入角色 ARN** 输入现有执行角色的 Amazon 资源名称（ARN）。

1. 选择**下一步**。

### 步骤 3：查看和创建
<a name="create-environment-start-review"></a>

**要查看环境摘要，请执行以下操作**
+ 查看环境摘要，选择**创建环境**。
**注意**  
创建环境大约需要二十到三十分钟。