

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

# 安装自定义插件
<a name="configuring-dag-import-plugins"></a>

Amazon MWAA 支持 Apache Airflow 的内置插件管理器，允许您使用自定义 Apache Airflow 运算符、挂钩、传感器或接口。本页介绍使用 `plugins.zip` 文件在 Amazon MWAA 环境中安装 [Apache Airflow 自定义插件](https://airflow.incubator.apache.org/plugins.html)的步骤。

**Contents**
+ [先决条件](#configuring-dag-plugins-prereqs)
+ [工作方式](#configuring-dag-plugins-how)
+ [何时使用插件](#configuring-dag-plugins-changed)
+ [自定义插件概述](#configuring-dag-plugins-overview)
  + [自定义插件目录和大小限制](#configuring-dag-plugins-quota)
+ [自定义插件示例](#configuring-dag-plugins-airflow-ex)
  + [在 plugins.zip 中使用平面目录结构的示例](#configuring-dag-plugins-overview-simple)
  + [在 plugins.zip 中使用平面目录结构的示例](#configuring-dag-plugins-overview-complex)
+ [创建 plugins.zip 文件](#configuring-dag-plugins-test-create)
  + [步骤 1：使用 Amazon MWAA CLI 实用工具测试自定义插件](#configuring-dag-plugins-cli-utility)
  + [步骤 2：创建 plugins.zip 文件](#configuring-dag-plugins-zip)
+ [上传 `plugins.zip` 到 Amazon S3](#configuring-dag-plugins-upload)
  + [使用 AWS CLI](#configuring-dag-plugins-upload-cli)
  + [使用 Amazon S3 控制台](#configuring-dag-plugins-upload-console)
+ [在环境中安装自定义插件](#configuring-dag-plugins-mwaa-installing)
  + [在 Amazon MWAA 控制台上指定 `plugins.zip` 的路径（第一次）](#configuring-dag-plugins-mwaa-first)
  + [在 Amazon MWAA 控制台上指定 `plugins.zip` 的版本](#configuring-dag-plugins-s3-mwaaconsole)
+ [plugins.zip 的用例示例](#configuring-dag-plugins-examples)
+ [接下来做什么？](#configuring-dag-plugins-next-up)

## 先决条件
<a name="configuring-dag-plugins-prereqs"></a>

在完成本页上的步骤之前，您需要具备以下条件。
+ **权限** — 您的 AWS 账户 必须已获得管理员授权，访问适用于环境的 [AmazonMWAAFullConsoleAccess](access-policies.md#console-full-access) 访问控制策略。此外，[执行角色](mwaa-create-role.md)必须允许 Amazon MWAA 环境访问环境所使用的 AWS 资源。
+ **访问权限** — 如果您需要访问公共存储库以便直接在 Web 服务器上安装依赖项，则必须将环境配置为具有**公共网络** Web 服务器访问权限。有关更多信息，请参阅[Apache Airflow 访问模式](configuring-networking.md)。
+ **Amazon S3 配置** — 用于存储 DAG 的 [Amazon S3 存储桶](mwaa-s3-bucket.md)、在 `plugins.zip` 中的自定义插件和在 `requirements.txt` 中的 Python 依赖项必须配置为*已阻止公共访问*和*已启用版本控制*。

## 工作方式
<a name="configuring-dag-plugins-how"></a>

要在环境中运行自定义插件，您必须做三件事：

1. 在本地创建 `plugins.zip` 文件。

1. 将 `plugins.zip` 文件上传到 Amazon S3 中的存储桶。

1. 在 Amazon MWAA 控制台的**插件文件**字段中指定此文件的版本。

**注意**  
如果这是您首次将 `plugins.zip` 上传到 Amazon S3 存储桶，则还需要在 Amazon MWAA 控制台上指定文件路径。您只需要完成此步骤一次。

## 何时使用插件
<a name="configuring-dag-plugins-changed"></a>

正如 [Apache Airflow 文档](https://airflow.apache.org/docs/apache-airflow/stable/authoring-and-scheduling/plugins.html#plugins)中所述，仅在扩展 Apache Airflow 用户界面时才需要插件。可以直接将自定义操作符与 `DAG` 代码一起放入 `/dags` 文件夹中。

如果需要自行创建与外部系统的集成，请将其放在 /`dags` 文件夹或其中的子文件夹中，而不是放在 `plugins.zip` 文件夹中。在 Apache Airflow 2.x 中，插件主要用于扩展 UI。

同样，不能将其他依赖项放入 `plugins.zip` 中。而可以将其存储在 Amazon S3 `/dags` 文件夹中的某个位置，在 Apache Airflow 启动之前，这些依赖项将在该位置同步到每个 Amazon MWAA 容器。

**注意**  
`/dags` 文件夹或 `plugins.zip` 中任何未显式定义 Apache Airflow DAG 对象的文件都必须在 `.airflowignore` 文件中列出。

## 自定义插件概述
<a name="configuring-dag-plugins-overview"></a>

Apache Airflow 的内置插件管理器只需将文件拖放到 `$AIRFLOW_HOME/plugins` 文件夹中即可将外部功能集成到其核心中。它允许您使用自定义 Apache Airflow 运算符、钩子、传感器或接口。下一节提供了本地开发环境中平面和嵌套目录结构的示例，以及生成的 import 语句，这些语句决定了 plugins.zip 中的目录结构。

### 自定义插件目录和大小限制
<a name="configuring-dag-plugins-quota"></a>

在启动期间，Apache Airflow 计划程序和工作线程在 `/usr/local/airflow/plugins/{{*}}` 中环境 AWS 托管的 Fargate 容器中搜索自定义插件。
+ **目录结构**。目录结构（在 `/{{*}}` 中）基于您 `plugins.zip` 文件的内容。例如，如果 `plugins.zip` 包含 `operators` 目录作为主级目录，则该目录将被解压缩到环境的 `/usr/local/airflow/plugins/{{operators}}` 中。
+ **大小限制**。我们建议使用小于 1 GB 的 `plugins.zip` 文件。`plugins.zip` 文件大小越大，环境的启动时间就越长。尽管 Amazon MWAA 没有明确限制 `plugins.zip` 文件的大小，但如果无法在十分钟内安装依赖项，Fargate 服务将超时并尝试将环境回滚到稳定状态。

**注意**  
对于使用 Apache Airflow v2.0.2 的环境，Amazon MWAA 会限制 Apache Airflow Web 服务器上的出站流量，并且不允许直接在 Web 服务器上安装插件或 Python 依赖项。从 Apache Airflow v2.2.2 开始，Amazon MWAA 可以直接在 Web 服务器上安装插件和依赖项。

## 自定义插件示例
<a name="configuring-dag-plugins-airflow-ex"></a>

下一节使用*《Apache Airflow 参考指南》*中的示例代码来说明如何构建本地开发环境。

### 在 plugins.zip 中使用平面目录结构的示例
<a name="configuring-dag-plugins-overview-simple"></a>

------
#### [ Apache Airflow v3 ]

以下示例显示了 Apache Airflow v3 中一个采用扁平目录结构的 `plugins.zip` 文件。

**Example 带 `PythonVirtualenvOperator` plugins.zip 的扁平目录**  
以下示例显示 [为 Apache Airflow PythonVirtualenvOperator 创建自定义插件](samples-virtualenv.md) 中 `PythonVirtualenvOperator` 自定义插件的 plugins.zip 文件的主级树。  

```
├── virtual_python_plugin.py
```

**Example plugins/virtual\_python\_plugin.py**  
以下示例显示 `PythonVirtualenvOperator` 自定义插件。  

```
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from airflow.plugins_manager import AirflowPlugin
import airflow.utils.python_virtualenv 
from typing import List

def _generate_virtualenv_cmd(tmp_dir: str, python_bin: str, system_site_packages: bool) -> List[str]:
    cmd = ['python3','/usr/local/airflow/.local/lib/python3.7/site-packages/virtualenv', tmp_dir]
    if system_site_packages:
        cmd.append('--system-site-packages')
    if python_bin is not None:
        cmd.append(f'--python={python_bin}')
    return cmd

airflow.utils.python_virtualenv._generate_virtualenv_cmd=_generate_virtualenv_cmd

class VirtualPythonPlugin(AirflowPlugin):                
    name = 'virtual_python_plugin'
```

------
#### [ Apache Airflow v2 ]

以下示例显示了 Apache Airflow v2 中一个采用扁平目录结构的 `plugins.zip` 文件。

**Example 带 `PythonVirtualenvOperator` plugins.zip 的扁平目录**  
以下示例显示 [为 Apache Airflow PythonVirtualenvOperator 创建自定义插件](samples-virtualenv.md) 中 `PythonVirtualenvOperator` 自定义插件的 plugins.zip 文件的主级树。  

```
├── virtual_python_plugin.py
```

**Example plugins/virtual\_python\_plugin.py**  
以下示例显示 `PythonVirtualenvOperator` 自定义插件。  

```
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from airflow.plugins_manager import AirflowPlugin
import airflow.utils.python_virtualenv 
from typing import List

def _generate_virtualenv_cmd(tmp_dir: str, python_bin: str, system_site_packages: bool) -> List[str]:
    cmd = ['python3','/usr/local/airflow/.local/lib/python3.7/site-packages/virtualenv', tmp_dir]
    if system_site_packages:
        cmd.append('--system-site-packages')
    if python_bin is not None:
        cmd.append(f'--python={python_bin}')
    return cmd

airflow.utils.python_virtualenv._generate_virtualenv_cmd=_generate_virtualenv_cmd

class VirtualPythonPlugin(AirflowPlugin):                
    name = 'virtual_python_plugin'
```

------

### 在 plugins.zip 中使用平面目录结构的示例
<a name="configuring-dag-plugins-overview-complex"></a>

------
#### [ Apache Airflow v3 ]

以下示例显示一个 `plugins.zip` 文件，其中包含 `hooks`、`operators` 的单独目录和 `sensors` 目录。

**Example Plugins.zip**  

```
__init__.py
my_airflow_plugin.py
 hooks/
  |-- __init__.py
  |-- my_airflow_hook.py
 operators/
  |-- __init__.py
  |-- my_airflow_operator.py
  |-- hello_operator.py
 sensors/
  |-- __init__.py
  |-- my_airflow_sensor.py
```

以下示例显示使用自定义插件的 DAG（[DAG 文件夹](https://docs.aws.amazon.com/mwaa/latest/userguide/configuring-dag-folder.html#configuring-dag-folder-how)）中的导入语句。

**Example dags/your\_dag.py**  

```
from airflow import DAG
from datetime import datetime, timedelta
from operators.my_airflow_operator import MyOperator
from sensors.my_airflow_sensor import MySensor
from operators.hello_operator import HelloOperator

default_args = {
	'owner': 'airflow',
	'depends_on_past': False,
	'start_date': datetime(2018, 1, 1),
	'email_on_failure': False,
	'email_on_retry': False,
	'retries': 1,
	'retry_delay': timedelta(minutes=5),
}


with DAG('customdag',
		 max_active_runs=3,
		 schedule_interval='@once',
		 default_args=default_args) as dag:

	sens = MySensor(
		task_id='taskA'
	)

	op = MyOperator(
		task_id='taskB',
		my_field='some text'
	)

	hello_task = HelloOperator(task_id='sample-task', name='foo_bar')



	sens >> op >> hello_task
```

**Example plugins/my\_airflow\_plugin.py**  

```
from airflow.plugins_manager import AirflowPlugin
from hooks.my_airflow_hook import *
from operators.my_airflow_operator import *
                    
class PluginName(AirflowPlugin):
                    
    name = 'my_airflow_plugin'
                    
    hooks = [MyHook]
    operators = [MyOperator]
    sensors = [MySensor]
```

以下示例显示自定义插件文件中所需的每条导入语句。

**Example hooks/my\_airflow\_hook.py**  

```
from airflow.hooks.base import BaseHook


class MyHook(BaseHook):

    def my_method(self):
        print("Hello World")
```

**Example sensors/my\_airflow\_sensor.py**  

```
from airflow.sensors.base import BaseSensorOperator
from airflow.utils.decorators import apply_defaults


class MySensor(BaseSensorOperator):

    @apply_defaults
    def __init__(self,
                 *args,
                 **kwargs):
        super(MySensor, self).__init__(*args, **kwargs)

    def poke(self, context):
        return True
```

**Example operators/my\_airflow\_operator.py**  

```
from airflow.operators.bash import BaseOperator
from airflow.utils.decorators import apply_defaults
from hooks.my_airflow_hook import MyHook


class MyOperator(BaseOperator):

    @apply_defaults
    def __init__(self,
                 my_field,
                 *args,
                 **kwargs):
        super(MyOperator, self).__init__(*args, **kwargs)
        self.my_field = my_field

    def execute(self, context):
        hook = MyHook('my_conn')
        hook.my_method()
```

**Example operators/hello\_operator.py**  

```
from airflow.models.baseoperator import BaseOperator
from airflow.utils.decorators import apply_defaults

class HelloOperator(BaseOperator):

    @apply_defaults
    def __init__(
            self,
            name: str,
            **kwargs) -> None:
        super().__init__(**kwargs)
        self.name = name

    def execute(self, context):
        message = "Hello {}".format(self.name)
        print(message)
        return message
```

按照[使用 Amazon MWAA CLI 实用工具测试自定义插件](#configuring-dag-plugins-cli-utility)中的步骤进行操作，然后[创建 plugins.zip 文件](#configuring-dag-plugins-zip)来将内容压缩到 `plugins` 目录**之内**。例如 `cd plugins`。

------
#### [ Apache Airflow v2 ]

以下示例显示一个 `plugins.zip` 文件，其中包含 `hooks`、`operators` 的单独目录和 `sensors` 目录。

**Example Plugins.zip**  

```
__init__.py
 my_airflow_plugin.py
 hooks/
  |-- __init__.py
  |-- my_airflow_hook.py
 operators/
  |-- __init__.py
  |-- my_airflow_operator.py
  |-- hello_operator.py
 sensors/
  |-- __init__.py
  |-- my_airflow_sensor.py
```

以下示例显示使用自定义插件的 DAG（[DAG 文件夹](https://docs.aws.amazon.com/mwaa/latest/userguide/configuring-dag-folder.html#configuring-dag-folder-how)）中的导入语句。

**Example dags/your\_dag.py**  

```
from airflow import DAG
from datetime import datetime, timedelta
from operators.my_airflow_operator import MyOperator
from sensors.my_airflow_sensor import MySensor
from operators.hello_operator import HelloOperator

default_args = {
	'owner': 'airflow',
	'depends_on_past': False,
	'start_date': datetime(2018, 1, 1),
	'email_on_failure': False,
	'email_on_retry': False,
	'retries': 1,
	'retry_delay': timedelta(minutes=5),
}


with DAG('customdag',
		 max_active_runs=3,
		 schedule_interval='@once',
		 default_args=default_args) as dag:

	sens = MySensor(
		task_id='taskA'
	)

	op = MyOperator(
		task_id='taskB',
		my_field='some text'
	)

	hello_task = HelloOperator(task_id='sample-task', name='foo_bar')



	sens >> op >> hello_task
```

**Example plugins/my\_airflow\_plugin.py**  

```
from airflow.plugins_manager import AirflowPlugin
from hooks.my_airflow_hook import *
from operators.my_airflow_operator import *
                    
class PluginName(AirflowPlugin):
                    
    name = 'my_airflow_plugin'
                    
    hooks = [MyHook]
    operators = [MyOperator]
    sensors = [MySensor]
```

以下示例显示自定义插件文件中所需的每条导入语句。

**Example hooks/my\_airflow\_hook.py**  

```
from airflow.hooks.base import BaseHook


class MyHook(BaseHook):

    def my_method(self):
        print("Hello World")
```

**Example sensors/my\_airflow\_sensor.py**  

```
from airflow.sensors.base import BaseSensorOperator
from airflow.utils.decorators import apply_defaults


class MySensor(BaseSensorOperator):

    @apply_defaults
    def __init__(self,
                 *args,
                 **kwargs):
        super(MySensor, self).__init__(*args, **kwargs)

    def poke(self, context):
        return True
```

**Example operators/my\_airflow\_operator.py**  

```
from airflow.operators.bash import BaseOperator
from airflow.utils.decorators import apply_defaults
from hooks.my_airflow_hook import MyHook


class MyOperator(BaseOperator):

    @apply_defaults
    def __init__(self,
                 my_field,
                 *args,
                 **kwargs):
        super(MyOperator, self).__init__(*args, **kwargs)
        self.my_field = my_field

    def execute(self, context):
        hook = MyHook('my_conn')
        hook.my_method()
```

**Example operators/hello\_operator.py**  

```
from airflow.models.baseoperator import BaseOperator
from airflow.utils.decorators import apply_defaults

class HelloOperator(BaseOperator):

    @apply_defaults
    def __init__(
            self,
            name: str,
            **kwargs) -> None:
        super().__init__(**kwargs)
        self.name = name

    def execute(self, context):
        message = "Hello {}".format(self.name)
        print(message)
        return message
```

按照[使用 Amazon MWAA CLI 实用工具测试自定义插件](#configuring-dag-plugins-cli-utility)中的步骤进行操作，然后[创建 plugins.zip 文件](#configuring-dag-plugins-zip)来将内容压缩到 `plugins` 目录**之内**。例如 `cd plugins`。

------

## 创建 plugins.zip 文件
<a name="configuring-dag-plugins-test-create"></a>

以下步骤描述了我们建议在本地创建 plugins.zip 文件的步骤。

### 步骤 1：使用 Amazon MWAA CLI 实用工具测试自定义插件
<a name="configuring-dag-plugins-cli-utility"></a>
+ 命令行界面 (CLI) 实用工具可在本地复制 Amazon MWAA 环境。
+ CLI 在本地构建 Docker 容器镜像，类似于 Amazon MWAA 生产镜像。您可以使用它运行本地 Apache Airflow 环境来开发和测试 DAG、自定义插件和依赖项，然后部署到 Amazon MWAA。
+ 要运行 CLI，请参阅 GitHub 上的 [aws-mwaa-docker-images](https://github.com/aws/amazon-mwaa-docker-images)。

### 步骤 2：创建 plugins.zip 文件
<a name="configuring-dag-plugins-zip"></a>

您可以使用内置的 ZIP 存档实用工具或任何其他 ZIP 实用工具（例如 [7zip](https://www.7-zip.org/download.html)）来创建.zip 文件。

**注意**  
当您创建 .zip 文件时，Windows 操作系统的内置 ZIP 实用工具可能会添加子文件夹。我们建议您验证 plugins.zip 文件的内容，然后再上传到 Amazon S3 存储桶，以确保没有添加其他目录。

1. 将目录更改为本地 Airflow 插件目录。例如：

   ```
   myproject$ cd plugins
   ```

1. 运行以下命令以确保内容具有可执行权限（仅限 macOS 和 Linux）。

   ```
   plugins$ chmod -R 755 .
   ```

1. 将内容压缩到 `plugins` 文件夹中****。

   ```
   plugins$ zip -r plugins.zip .
   ```

## 上传 `plugins.zip` 到 Amazon S3
<a name="configuring-dag-plugins-upload"></a>

您可以使用 Amazon S3 控制台或 AWS Command Line Interface (AWS CLI) 将 `plugins.zip` 文件上传到 Amazon S3 存储桶中。

### 使用 AWS CLI
<a name="configuring-dag-plugins-upload-cli"></a>

AWS Command Line Interface (AWS CLI) 是一种开源工具，您可以用来在命令行 Shell 中使用命令与 AWS 服务进行交互。要完成本节中的步骤，您需要以下满足以下条件：
+ [AWS CLI – 安装版本 2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)。
+ [AWS CLI – 使用 `aws configure` 进行快速配置](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)。

**要使用 AWS CLI 上传，请执行以下操作**

1. 在命令提示符下，导航到存储 `plugins.zip` 文件的目录。例如：

   ```
   cd plugins
   ```

1. 以下示例列出所有 Amazon S3 存储桶。

   ```
   aws s3 ls
   ```

1. 使用以下命令列出 Amazon S3 存储桶中适合环境的文件和文件夹。

   ```
   aws s3 ls s3://{{YOUR_S3_BUCKET_NAME}}
   ```

1. 使用以下命令将 `plugins.zip` 文件上传到环境的 Amazon S3 存储桶。

   ```
   aws s3 cp plugins.zip s3://{{amzn-s3-demo-bucket}}/plugins.zip
   ```

### 使用 Amazon S3 控制台
<a name="configuring-dag-plugins-upload-console"></a>

Amazon S3 控制台是一个基于 Web 的用户界面，可用来创建和管理 Amazon S3 存储桶中的资源。

**要使用 Amazon S3 控制台上传，请执行以下操作**

1. 在 Amazon MWAA 控制台上打开[环境页面](https://console.aws.amazon.com/mwaa/home#/environments)。

1. 选择环境。

1. 在 **S3 中的 DAG 代码**窗格中选择 **S3 存储桶**链接，在控制台上打开存储桶。

1. 选择**上传**。

1. 选择 **添加文件**。

1. 选择 `plugins.zip` 的本地副本，选择**上传**。

## 在环境中安装自定义插件
<a name="configuring-dag-plugins-mwaa-installing"></a>

本节介绍如何安装您上传到 Amazon S3 存储桶的自定义插件，方法是指定 plugins.zip 文件的路径，并在每次更新 zip 文件时指定 plugins.zip 文件的版本。

### 在 Amazon MWAA 控制台上指定 `plugins.zip` 的路径（第一次）
<a name="configuring-dag-plugins-mwaa-first"></a>

如果这是您首次将 `plugins.zip` 上传到 Amazon S3 存储桶，则还需要在 Amazon MWAA 控制台上指定文件路径。您只需要完成此步骤一次。

1. 在 Amazon MWAA 控制台上打开[环境页面](https://console.aws.amazon.com/mwaa/home#/environments)。

1. 选择环境。

1. 选择**编辑**。

1. 在 **Amazon S3 中的 DAG 代码**窗格上，选择**要求文件 - 可选**字段旁边的**浏览 S3**。

1. 选择 Amazon S3 存储桶中的 `plugins.zip` 文件。

1. 选择**选择**。

1. 选择**下一步**、**更新环境**。

### 在 Amazon MWAA 控制台上指定 `plugins.zip` 的版本
<a name="configuring-dag-plugins-s3-mwaaconsole"></a>

每次在 Amazon S3 存储桶中上传 `plugins.zip` 的新版本时，都需要在 Amazon MWAA 控制台上指定 `plugins.zip` 文件的版本。

1. 在 Amazon MWAA 控制台上打开[环境页面](https://console.aws.amazon.com/mwaa/home#/environments)。

1. 选择环境。

1. 选择**编辑**。

1. 在 **Amazon S3 中的 DAG 代码**窗格中，从下拉列表中选择 `plugins.zip` 的版本。

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

## plugins.zip 的用例示例
<a name="configuring-dag-plugins-examples"></a>
+ 要了解如何创建自定义插件，请参阅 [使用 Apache Hive 和 Hadoop 的自定义插件](samples-hive.md)。
+ 要了解如何创建自定义插件，请参阅 [修补 PythonVirtualenvOperator 的自定义插件 ](samples-virtualenv.md)。
+ 要了解如何创建自定义插件，请参阅 [使用 Oracle 定制插件](samples-oracle.md)。
+ 要了解如何创建自定义插件，请参阅 [在 Amazon MWAA 上更改 DAG 的时区](samples-plugins-timezone.md)。

## 接下来做什么？
<a name="configuring-dag-plugins-next-up"></a>

使用 GitHub 上的 [aws-mwaa-docker-images](https://github.com/aws/amazon-mwaa-docker-images) 在本地测试 DAG、自定义插件和 Python 依赖项。