

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

# 在您的帳戶中註冊第三方私有擴充功能
<a name="registry-register-private-extension"></a>

本主題涵蓋註冊與您共用的第三方私有擴充功能的步驟，使其可在您的帳戶中使用。

**注意**  
在繼續之前，請確認您擁有註冊私有擴充功能所需的 [IAM 許可](registry-private.md#registry-register-permissions)。

**註冊與您共用的私有擴充功能 (AWS CLI)**

1. 找出包含您想在帳戶中註冊之私有擴充功能專案套件的 Amazon S3 儲存貯體。

1. 使用 [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/register-type.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/register-type.html) 命令在帳戶中註冊擴充功能。

   例如，以下命令會在指定的 AWS 帳戶中註冊 `My::Resource::Example` 資源類型：

   ```
   aws cloudformation register-type --type RESOURCE \
     --type-name My::Resource::Example \
     --schema-handler-package [s3 object path] --region us-west-2
   ```

   `RegisterType` 是一種非同步操作，會傳回您可以用來追蹤註冊請求進度的註冊權杖。

   ```
   {
       "RegistrationToken": "f5525280-104e-4d35-bef5-8f1fexample"
   }
   ```

   如果您的延伸模組呼叫 AWS APIs做為其功能的一部分，您必須建立 IAM 執行角色，其中包含呼叫這些 AWS APIs的必要許可，並在您的帳戶中佈建該執行角色。然後您可以使用 `--execution-role-arn` 選項來指定此執行角色。CloudFormation 接著會取得該執行角色，為您的資源類型提供適當的憑證。

   ```
   --execution-role-arn arn:aws:iam::123456789012:role/MyIAMRole
   ```

1. (選用) 搭配 [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/describe-type-registration.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/describe-type-registration.html) 命令使用註冊字符，追蹤您註冊請求的進度。

   當 CloudFormation 完成註冊請求時，會將請求的進度狀態設為 `COMPLETE`。

   以下範例會使用以上 `describe-type-registration` 命令傳回的註冊權杖來傳回註冊狀態資訊。

   ```
   aws cloudformation describe-type-registration \
     --registration-token f5525280-104e-4d35-bef5-8f1fexample \
     --region us-west-2
   ```

   命令會傳回下列輸出：

   ```
   {
       "ProgressStatus": "COMPLETE",
       "TypeArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Resource-Example",
       "Description": "Deployment is currently in DEPLOY_STAGE of status COMPLETED; ",
       "TypeVersionArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Resource-Example/00000001"
   }
   ```

**重要**  
若您要註冊的擴充功能是勾點，則必須執行下一個步驟。您必須為 `HookInvocationStatus` 屬性指定 `ENABLED`。此操作將啟用勾點結構描述 `properties` 區段中定義的掛鉤屬性。有關詳細資訊，請參閱《CloudFormation Hooks 使用者指南**》中的[勾點組態結構描述語法參考](https://docs.aws.amazon.com/cloudformation-cli/latest/hooks-userguide/hook-configuration-schema.html)。

**若要指定勾點 (AWS CLI) 的組態資料**

1. 取得勾點的 ARN 並儲存。您可以使用 AWS 管理主控台 或 取得勾點的 ARN AWS CLI。如需更多資訊，請參閱[在 CloudFormation 登錄檔中檢視可用的與已啟用擴充功能](registry-view.md)。

   ```
   export HOOK_TYPE_ARN="arn:aws:cloudformation:us-west-2:123456789012:type/hook/Organization-Service-Hook/"
   ```

1. 若要指定組態資料，請使用 [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) 命令。您為 `--configuration` 傳遞的 JSON 必須根據勾點的組態結構描述進行驗證。要啟用勾點，您必須在 `HookConfiguration` 區段將 `HookInvocationStatus` 屬性設定為 `ENABLED`。

   ```
   aws cloudformation set-type-configuration \
     --configuration "{"CloudFormationConfiguration":{"HookConfiguration":{"HookInvocationStatus": "ENABLED", "FailureMode": "FAIL", "Properties":{}}}}" \
     --type-arn $HOOK_TYPE_ARN --region us-west-2
   ```

   有關詳細資訊，請參閱《CloudFormation Hooks 使用者指南**》中的[勾點組態結構描述語法參考](https://docs.aws.amazon.com/cloudformation-cli/latest/hooks-userguide/hook-configuration-schema.html)。