

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 開發自訂 CloudFormation 勾點的先決條件
<a name="hooks-prerequisites"></a>

您可以使用 Java 或 Python 開發自訂勾點。以下是開發自訂勾點的先決條件：

**Java 先決條件**
+ [Apache Maven](https://maven.apache.org/install.html)
+ [JDK 17](https://www.oracle.com/java/technologies/downloads/#java17)
**注意**  
如果您想要使用 [CloudFormation 命令列界面 (CLI)](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/what-is-cloudformation-cli.html) 啟動 Java 的 Hooks 專案，您也必須安裝 Python 3.8 或更新版本。CloudFormation CLI 的 Java 外掛程式可以透過 `pip`(Python 的套件管理員） 安裝，該程式使用 Python 解散。

若要為 Java Hooks 專案實作 Hook 處理常式，您可以下載 [Java Hook 處理常式範例檔案](samples/java-handlers.zip)。

**Python 先決條件**
+ [Python 3.8 版或更新版本。](https://www.python.org/downloads/)

若要為 Python Hooks 專案實作 Hook 處理常式，您可以下載 [Python Hook 處理常式範例檔案](samples/python-handlers.zip)。

## 開發勾點的許可
<a name="hooks-development-permissions"></a>

除了 CloudFormation `Create`、 `Update`和 `Delete`堆疊許可之外，您還需要存取下列 AWS CloudFormation 操作。存取這些操作是透過 IAM 角色的 CloudFormation 政策來管理。
+ [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/register-type.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/register-type.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/list-types.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/list-types.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/deregister-type.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/deregister-type.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/set-type-configuration.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/set-type-configuration.html)

如需詳細資訊，請參閱[授予 CloudFormation Hooks 的 IAM 許可](grant-iam-permissions-for-hooks.md)。

## 設定 Hooks 的開發環境
<a name="hooks-environment"></a>

若要開發勾點，您應該熟悉 [CloudFormation 範本](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html)，以及 Python 或 Java。

 

**若要安裝 CloudFormation CLI 和相關聯的外掛程式：**

1. 使用 Python 套件管理員 `pip`，安裝 CloudFormation CLI。

   ```
   pip3 install cloudformation-cli
   ```

1. 安裝 CloudFormation CLI 的 Python 或 Java 外掛程式。

------
#### [ Python ]

   ```
   pip3 install cloudformation-cli-python-plugin
   ```

------
#### [ Java ]

   ```
   pip3 install cloudformation-cli-java-plugin
   ```

------

若要升級 CloudFormation CLI 和外掛程式，您可以使用升級選項。

------
#### [ Python ]

```
pip3 install --upgrade cloudformation-cli cloudformation-cli-python-plugin
```

------
#### [ Java ]

```
pip3 install --upgrade cloudformation-cli cloudformation-cli-java-plugin
```

------