

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

# 使用 CloudFormation 创建资源管理器资源
<a name="cloudformation-support"></a>

Amazon Resource Explorer 与 Amazon CloudFormation 集成，后者是一项可帮助您建模和设置 Amazon 资源的服务。此集成可帮助您花费更少的时间来创建和管理您的资源和基础设施。您可以创建一个描述所需的全部 Amazon 资源的模板，CloudFormation 将为您预调配和配置这些资源。资源的示例包括索引、视图或为 Amazon Web Services 区域 进行的默认视图分配。

在您使用 CloudFormation 时，可重复使用您的模板来不断地重复设置您的资源管理器资源。描述您的资源一次，然后在多个 Amazon Web Services 账户 和区域中反复预调配相同的资源。

**使用 Amazon CloudFormation 将资源管理器部署到 Amazon Organizations**  
您可以使用 Amazon CloudFormation StackSets 将资源管理器部署到组织中的所有账户。当您在组织中添加或创建成员账户时，StackSets 可以自动将每个 Amazon Web Services 区域 的索引配置到新的成员账户，包括您指定的聚合器索引。有关说明，请参阅 [为组织中的账户部署资源管理器](manage-service-all-org-with-stacksets.md)。

## 资源管理器和 CloudFormation 模板
<a name="working-with-templates"></a>

要为资源管理器和相关服务预调配和配置资源，您必须了解 [Amazon CloudFormation 模板](https://docs.amazonaws.cn/AWSCloudFormation/latest/UserGuide/template-guide.html)。模板是 JSON 或 YAML 格式的文本文件。这些模板描述要在 CloudFormation 堆栈中预调配的资源。如果您不熟悉 JSON 或 YAML，可以在 Amazon CloudFormation Designer 的帮助下开始使用 CloudFormation 模板。有关更多信息，请参阅*Amazon CloudFormation用户指南*中的[什么是 Amazon CloudFormation Designer？](https://docs.amazonaws.cn/AWSCloudFormation/latest/UserGuide/working-with-templates-cfn-designer.html)。

资源管理器支持在 CloudFormation 中创建以下资源类型：
+ **[索引](https://docs.amazonaws.cn/AWSCloudFormation/latest/UserGuide/aws-resource-resourceexplorer2-index.html)** – 在区域中创建索引并在该区域开启资源管理器。您可以将索引指定为 Amazon Web Services 账户 的本地索引或聚合器索引。有关更多信息，请参阅 [在中打开资源管理器 Amazon Web Services 区域 以索引您的资源](manage-service-turn-on-region.md) 和 [通过创建聚合器索引开启跨区域搜索](manage-aggregator-region.md)：
+ **[视图](https://docs.amazonaws.cn/AWSCloudFormation/latest/UserGuide/aws-resource-resourceexplorer2-view.html)** – 创建一个视图，用于确定用户执行搜索时可以显示哪些结果。每个搜索操作都必须指定一个视图。您必须授予用户使用您希望他们访问的视图的权限。有关更多信息，请参阅[管理资源管理器视图以提供搜索访问权限](manage-views.md)。
**注意**  
必须先在某个区域中创建索引，然后才能在该区域中创建视图。如果您创建索引和视图作为同一个堆栈的一部分，请使用视图上的 `DependsOn` 属性，如以下示例模板所示，以确保首先创建索引。
+ **[DefaultViewAssociation](https://docs.amazonaws.cn/AWSCloudFormation/latest/UserGuide/aws-resource-resourceexplorer2-defaultviewassociation.html)** – 将指定的视图分配为其区域中的默认视图。当用户未明确指定用于搜索操作的视图时，资源管理器会尝试使用与用户执行搜索所在区域关联的默认视图。有关更多信息，请参阅[在 Amazon Web Services 区域 中设置默认视图](manage-views-set-default.md)。

以下示例说明了如何在同一个区域中创建一个索引和一个视图，并将该视图设置为该区域的默认视图。

**YAML**

```
Description: >-
  Sample CFN Stack setting up Resource Explorer with an aggregator index and a default view 
Resources:
  SampleIndex:
    Type: 'AWS::ResourceExplorer2::Index'
    Properties:
      Type: AGGREGATOR
      Tags:
        Purpose: ResourceExplorer Sample CFN Stack
  SampleView:
    Type: 'AWS::ResourceExplorer2::View'
    Properties:
      ViewName: mySampleView
      IncludedProperties:
        - Name: tags
      Tags:
        Purpose: ResourceExplorer Sample CFN Stack
    DependsOn: SampleIndex
  SampleDefaultViewAssociation:
    Type: 'AWS::ResourceExplorer2::DefaultViewAssociation'
    Properties:
      ViewArn: !Ref SampleView
```

**JSON**

```
{
    "Description": "Sample CFN Stack setting up Resource Explorer with an aggregator index and a default view ",
    "Resources": {
        "SampleIndex": {
            "Type": "AWS::ResourceExplorer2::Index",
            "Properties": {
                "Type": "AGGREGATOR",
                "Tags": {
                    "Purpose": "ResourceExplorer Sample Stack"
                }
            }
        },
        "SampleView": {
            "Type": "AWS::ResourceExplorer2::View",
            "Properties": {
                "ViewName": "mySampleView",
                "IncludedProperties": [
                    {
                        "Name": "tags"
                    }
                ],
                "Tags": {
                    "Purpose": "ResourceExplorer Sample CFN Stack"
                }
            },
            "DependsOn": "SampleIndex"
        },
        "SampleDefaultViewAssociation": {
            "Type": "AWS::ResourceExplorer2::DefaultViewAssociation",
            "Properties": {
                "ViewArn": {
                    "Ref": "SampleView"
                }
            }
        }
    }
}
```

有关更多信息（包括资源管理器索引和视图的 JSON 和 YAML 模板示例），请参阅《Amazon CloudFormation 用户指南》**中的 [ResourceExplorer2 资源类型参考](https://docs.amazonaws.cn/AWSCloudFormation/latest/UserGuide/AWS_ResourceExplorer2.html)。

## 了解有关 Amazon CloudFormation 的更多信息
<a name="learn-more-cloudformation"></a>

要了解有关 CloudFormation 的更多信息，请参阅以下资源：
+ [Amazon CloudFormation](https://www.amazonaws.cn/cloudformation/)
+ [Amazon CloudFormation 用户指南](https://docs.amazonaws.cn/AWSCloudFormation/latest/UserGuide/Welcome.html)
+ [Amazon CloudFormation 命令行界面用户指南](https://docs.amazonaws.cn/cloudformation-cli/latest/userguide/what-is-cloudformation-cli.html)