

# 在您的账户中注册第三方私有扩展。
<a name="registry-register-private-extension"></a>

本主题介绍了注册与您共享的第三方私有扩展，以便能够在您的账户中使用的步骤。

**注意**  
在继续操作之前，请确认您拥有注册私有扩展所需的 [IAM 权限](registry-private.md#registry-register-permissions)。

**注册与您共享的私有扩展（Amazon CLI）**

1. 找到包含要在您的账户中注册的私有扩展项目包的 Amazon S3 存储桶。

1. 使用 [https://docs.amazonaws.cn/cli/latest/reference/cloudformation/register-type.html](https://docs.amazonaws.cn/cli/latest/reference/cloudformation/register-type.html) 命令在您的账户中注册私有扩展。

   例如，以下命令在指定的 Amazon Web Services 账户中注册 `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"
   }
   ```

   如果您的扩展调用 Amazon API 作为其功能的一部分，您必须创建一个包含调用这些 Amazon API 所需的权限的 IAM 执行角色，并在您的账户中预置该执行角色。然后，您可以使用 `--execution-role-arn` 选项指定此执行角色。接下来，CloudFormation 担任该执行角色，以便为您的资源类型提供相应的凭证。

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

1. （可选）将注册令牌与 [https://docs.amazonaws.cn/cli/latest/reference/cloudformation/describe-type-registration.html](https://docs.amazonaws.cn/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` 部分中定义的挂钩属性。有关更多信息，请参阅《Amazon CloudFormation Hooks User Guide》**中的 [Hooks configuration schema syntax reference](https://docs.amazonaws.cn/cloudformation-cli/latest/hooks-userguide/hook-configuration-schema.html)。

**指定挂钩的配置数据（Amazon CLI）**

1. 获取并保存挂钩的 ARN。您可以使用 Amazon Web Services 管理控制台 或 Amazon CLI 获取挂钩的 ARN。有关更多信息，请参阅 [查看 CloudFormation 注册表中可用和已激活的扩展](registry-view.md)。

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

1. 使用 [https://docs.amazonaws.cn/cli/latest/reference/cloudformation/set-type-configuration.html](https://docs.amazonaws.cn/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}}
   ```

   有关更多信息，请参阅《Amazon CloudFormation Hooks User Guide》**中的 [Hooks configuration schema syntax reference](https://docs.amazonaws.cn/cloudformation-cli/latest/hooks-userguide/hook-configuration-schema.html)。