

# 使用 AWS CLI 的资源管理器示例
<a name="cli_resource-explorer-2_code_examples"></a>

以下代码示例演示如何通过将 AWS Command Line Interface与资源管理器结合使用，来执行操作和实现常见场景。

*操作是大型程序的代码摘录*，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `associate-default-view`
<a name="resource-explorer-2_AssociateDefaultView_cli_topic"></a>

以下代码示例演示了如何使用 `associate-default-view`。

**AWS CLI**  
**将资源管理器视图设置为其 AWS 区域的默认值**  
以下 `associate-default-view` 示例将视图（由其 ARN 指定）设置为调用该操作的 AWS 区域的默认视图。  

```
aws resource-explorer-2 associate-default-view \
    --view-arn arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-Main-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111
```
输出：  

```
{
    "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-Main-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111"
}
```
有关更多信息，请参阅《AWS 资源管理器用户指南》**中的[在 AWS 区域中设置默认视图](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-set-default.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [AssociateDefaultView](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/associate-default-view.html)。

### `batch-get-view`
<a name="resource-explorer-2_BatchGetView_cli_topic"></a>

以下代码示例演示了如何使用 `batch-get-view`。

**AWS CLI**  
**检索有关多个资源管理器视图的详细信息**  
以下 `batch-get-view` 示例显示了两个视图（由其 ARN 指定）的详细信息。使用空格分隔 --view-arn 参数中的多个 ARN。  

```
aws resource-explorer-2 batch-get-view \
    --view-arns arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-EC2-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222, \
                arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-Main-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111
```
输出：  

```
{
    "Views": [
        {
            "Filters": {
                "FilterString": "service:ec2"
            },
            "IncludedProperties": [
                {
                    "Name": "tags"
                }
            ],
            "LastUpdatedAt": "2022-07-13T21:33:45.249000+00:00",
            "Owner": "123456789012",
            "Scope": "arn:aws:iam::123456789012:root",
            "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-EC2-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222"
        },
        {
            "Filters": {
                "FilterString": ""
            },
            "IncludedProperties": [
                {
                    "Name": "tags"
                }
            ],
            "LastUpdatedAt": "2022-07-13T20:34:11.314000+00:00",
            "Owner": "123456789012",
            "Scope": "arn:aws:iam::123456789012:root",
            "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-Main-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111"
        }
    ]
    "Errors": []
}
```
有关视图的更多信息，请参阅《AWS 资源管理器**用户指南》中的[关于资源管理器视图](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-about.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [BatchGetView](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/batch-get-view.html)。

### `create-index`
<a name="resource-explorer-2_CreateIndex_cli_topic"></a>

以下代码示例演示了如何使用 `create-index`。

**AWS CLI**  
**通过创建索引在 AWS 区域中启用资源管理器**  
以下 `create-index` 示例在调用操作的 AWS 区域中创建了本地索引。如果您未指定值，AWS CLI 会自动生成一个随机 `client-token` 参数值，并将其包含在对 AWS 的调用中。  

```
aws resource-explorer-2 create-index \
    --region us-east-1
```
输出：  

```
{
    "Arn": "arn:aws:resource-explorer-2:us-east-1:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222c",
    "CreatedAt": "2022-11-01T20:00:59.149Z",
    "State": "CREATING"
}
```
创建本地索引后，您可以通过运行 [update-index-type](https://docs.aws.amazon.com/cli/latest/reference/resource-explorer-2/update-index-type.html) 命令将其转换为账户的聚合索引。  
有关更多信息，请参阅《AWS 资源管理器**用户指南》中的[在 AWS 区域中启用资源管理器以索引您的资源](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-register.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [CreateIndex](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/create-index.html)**。

### `create-view`
<a name="resource-explorer-2_CreateView_cli_topic"></a>

以下代码示例演示了如何使用 `create-view`。

**AWS CLI**  
**示例 1：为 AWS 区域中的索引创建未经筛选的视图**  
以下 `create-view` 示例在指定的 AWS 区域中创建了一个视图，该视图不经过任何筛选即可返回该区域中的所有结果。该视图在返回的结果中包含可选的“标签”字段。由于此视图是在包含聚合器索引的区域中创建的，因此它可以包括账户中包含资源管理器索引的所有区域中的结果。  

```
aws resource-explorer-2 create-view \
    --view-name My-Main-View \
    --included-properties Name=tags \
    --region us-east-1
```
输出：  

```
{
    "View": {
        "Filters": {
            "FilterString": ""
        },
        "IncludedProperties": [
            {
                "Name": "tags"
            }
        ],
        "LastUpdatedAt": "2022-07-13T20:34:11.314000+00:00",
        "Owner": "123456789012",
        "Scope": "arn:aws:iam::123456789012:root",
        "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-Main-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111"
    }
}
```
**示例 2：创建仅返回与 Amazon EC2 关联的资源的视图**  
以下 `create-view` 在 AWS 区域 `us-east-1` 中创建了一个视图，该视图仅返回该区域中与 Amazon EC2 服务关联的资源。该视图在返回的结果中包含可选的 `Tags` 字段。由于此视图是在包含聚合器索引的区域中创建的，因此它可以包括账户中包含资源管理器索引的所有区域中的结果。  

```
aws resource-explorer-2 create-view \
    --view-name My-EC2-Only-View \
    --included-properties Name=tags \
    --filters FilterString="service:ec2" \
    --region us-east-1
```
输出：  

```
{
    "View": {
        "Filters": {
            "FilterString": "service:ec2"
        },
        "IncludedProperties": [
            {
                "Name":"tags"
            }
        ],
        "LastUpdatedAt": "2022-07-13T21:35:09.059Z",
        "Owner": "123456789012",
        "Scope": "arn:aws:iam::123456789012:root",
        "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-EC2-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222"
    }
}
```
有关更多信息，请参阅《AWS 资源管理器用户指南》**中的[创建用于搜索的视图](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-create.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateView](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/create-view.html)。

### `delete-index`
<a name="resource-explorer-2_DeleteIndex_cli_topic"></a>

以下代码示例演示了如何使用 `delete-index`。

**AWS CLI**  
**关闭 AWS 区域中的资源管理器**  
以下 `delete-index` 示例删除了您发出请求的 AWS 区域中指定的资源管理器索引。  

```
aws resource-explorer-2 delete-index \
    --arn arn:aws:resource-explorer-2:us-west-2:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222 \
    --region us-west-2
```
输出：  

```
{
    "Arn": "arn:aws:resource-explorer-2:us-west-2:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222",
    "State": "DELETING"
}
```
有关删除索引的更多信息，请参阅《AWS 资源管理器用户指南》中的[在 AWS 区域中关闭 AWS 资源管理器](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-deregister.html)**。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [DeleteIndex](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/delete-index.html)**。

### `delete-view`
<a name="resource-explorer-2_DeleteView_cli_topic"></a>

以下代码示例演示了如何使用 `delete-view`。

**AWS CLI**  
**删除资源管理器视图**  
以下 `delete-view` 示例删除了一个视图（由其 ARN 指定）。  

```
aws resource-explorer-2 delete-view \
    --view-arn arn:aws:resource-explorer-2:us-east-1:123456789012:view/EC2-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111
```
输出：  

```
{
    "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/EC2-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111"
}
```
有关更多信息，请参阅《AWS 资源管理器用户指南》**中的[删除视图](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-delete.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteView](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/delete-view.html)。

### `disassociate-default-view`
<a name="resource-explorer-2_DisassociateDefaultView_cli_topic"></a>

以下代码示例演示了如何使用 `disassociate-default-view`。

**AWS CLI**  
**删除 AWS 区域的默认资源管理器视图**  
以下 `disassociate-default-view` 删除了您调用操作的 AWS 区域的默认资源管理器视图。执行此操作后，区域中的所有搜索操作都必须明确指定视图，否则操作将失败。  

```
aws resource-explorer-2 disassociate-default-view
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS 资源管理器用户指南》**中的[在 AWS 区域中设置默认视图](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-set-default.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DisassociateDefaultView](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/disassociate-default-view.html)。

### `get-default-view`
<a name="resource-explorer-2_GetDefaultView_cli_topic"></a>

以下代码示例演示了如何使用 `get-default-view`。

**AWS CLI**  
**检索资源管理器视图，该视图是其 AWS 区域的默认视图**  
以下 `get-default-view` 示例将检索您调用操作的 AWS 区域的默认视图的 ARN。  

```
aws resource-explorer-2 get-default-view
```
输出：  

```
{
    "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/default-view/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111"
}
```
有关更多信息，请参阅《AWS 资源管理器用户指南》**中的[在 AWS 区域中设置默认视图](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-set-default.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetDefaultView](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/get-default-view.html)。

### `get-index`
<a name="resource-explorer-2_GetIndex_cli_topic"></a>

以下代码示例演示了如何使用 `get-index`。

**AWS CLI**  
**示例 1：检索资源管理器聚合器索引的详细信息**  
以下 `get-index` 示例显示了指定 AWS 区域中资源管理器索引的详细信息。由于指定的区域包含账户的聚合器索引，因此输出会列出将数据复制到该区域索引中的区域。  

```
aws resource-explorer-2 get-index \
    --region us-east-1
```
输出：  

```
{
    "Arn": "arn:aws:resource-explorer-2:us-east-1:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111",
    "CreatedAt": "2022-07-12T18:59:10.503000+00:00",
    "LastUpdatedAt": "2022-07-13T18:41:58.799000+00:00",
    "ReplicatingFrom": [
        "ap-south-1",
        "us-west-2"
    ],
    "State": "ACTIVE",
    "Tags": {},
    "Type": "AGGREGATOR"
}
```
**示例 2：检索资源管理器本地索引的详细信息**  
以下 `get-index` 示例显示了指定 AWS 区域中资源管理器索引的详细信息。由于指定的区域包含本地索引，因此输出会列出将该区域索引中的数据复制到的区域。  

```
aws resource-explorer-2 get-index \
    --region us-west-2
```
输出：  

```
{
    "Arn": "arn:aws:resource-explorer-2:us-west-2:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222",
    "CreatedAt": "2022-07-12T18:59:10.503000+00:00",
    "LastUpdatedAt": "2022-07-13T18:41:58.799000+00:00",
    "ReplicatingTo": [
        "us-west-2"
    ],
    "State": "ACTIVE",
    "Tags": {},
    "Type": "LOCAL"
}
```
有关索引的更多信息，请参阅《AWS 资源管理器用户指南》中的[检查哪些 AWS 区域开启了资源管理器](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-check.html)**。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetIndex](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/get-index.html)。

### `get-view`
<a name="resource-explorer-2_GetView_cli_topic"></a>

以下代码示例演示了如何使用 `get-view`。

**AWS CLI**  
**检索有关资源管理器视图的详细信息**  
以下 `get-view` 示例显示了一个视图（由其 ARN 指定）的详细信息。  

```
aws resource-explorer-2 get-view \
    --view-arn arn:aws:resource-explorer-2:us-east-1:123456789012:view/EC2-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111
```
输出：  

```
{
  "Tags" : {},
  "View" : {
        "Filters" : {
            "FilterString" : "service:ec2"
        },
        "IncludedProperties" : [
            {
                "Name" : "tags"
            }
        ],
        "LastUpdatedAt" : "2022-07-13T21:33:45.249Z",
        "Owner" : "123456789012",
        "Scope" : "arn:aws:iam::123456789012:root",
        "ViewArn" : "arn:aws:resource-explorer-2:us-east-1:123456789012:view/EC2-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111"
  }
}
```
有关视图的更多信息，请参阅《AWS 资源管理器**用户指南》中的[关于资源管理器视图](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-about.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetView](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/get-view.html)。

### `list-indexes`
<a name="resource-explorer-2_ListIndexes_cli_topic"></a>

以下代码示例演示了如何使用 `list-indexes`。

**AWS CLI**  
**列出资源管理器中包含索引的 AWS 区域**  
以下 `list-indexes` 示例列出了资源管理器具有索引的所有区域的索引。响应指定了每个索引的类型、其 AWS 区域及其 ARN。  

```
aws resource-explorer-2 list-indexes
```
输出：  

```
{
    "Indexes": [
        {
            "Arn": "arn:aws:resource-explorer-2:us-west-2:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111",
            "Region": "us-west-2",
            "Type": "AGGREGATOR"
        },
        {
            "Arn": "arn:aws:resource-explorer-2:us-east-1:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222",
            "Region": "us-east-1",
            "Type": "LOCAL"
        },
        {
            "Arn": "arn:aws:resource-explorer-2:us-east-2:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE33333",
            "Region": "us-east-2",
            "Type": "LOCAL"
        },
        {
            "Arn": "arn:aws:resource-explorer-2:us-west-1:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE44444",
            "Region": "us-west-1",
            "Type": "LOCAL"
        }
    ]
}
```
有关索引的更多信息，请参阅《AWS 资源管理器用户指南》中的[检查哪些 AWS 区域开启了资源管理器](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-check.html)**。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListIndexes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/list-indexes.html)。

### `list-supported-resource-types`
<a name="resource-explorer-2_ListSupportedResourceTypes_cli_topic"></a>

以下代码示例演示了如何使用 `list-supported-resource-types`。

**AWS CLI**  
**列出资源管理器中包含索引的 AWS 区域**  
以下 `list-supported-resource-types` 示例列出了 &AREXlong; 当前支持的所有资源类型。示例响应中包含一个 `NextToken` 值，该值表示有更多输出可供通过其他调用进行检索。  

```
aws resource-explorer-2 list-supported-resource-types \
    --max-items 10
```
输出：  

```
{
    "ResourceTypes": [
        {
            "ResourceType": "cloudfront:cache-policy",
            "Service": "cloudfront"
        },
        {
            "ResourceType": "cloudfront:distribution",
            "Service": "cloudfront"
        },
        {
            "ResourceType": "cloudfront:function",
            "Service": "cloudfront"
        },
        {
            "ResourceType": "cloudfront:origin-access-identity",
            "Service": "cloudfront"
        },
        {
            "ResourceType": "cloudfront:origin-request-policy",
            "Service": "cloudfront"
        },
        {
            "ResourceType": "cloudfront:realtime-log-config",
            "Service": "cloudfront"
        },
        {
            "ResourceType": "cloudfront:response-headers-policy",
            "Service": "cloudfront"
        },
        {
            "ResourceType": "cloudwatch:alarm",
            "Service": "cloudwatch"
        },
        {
            "ResourceType": "cloudwatch:dashboard",
            "Service": "cloudwatch"
        },
        {
            "ResourceType": "cloudwatch:insight-rule",
            "Service": "cloudwatch"
        }
    ],
    "NextToken": "eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAxMH0="
}
```
要获取输出的下一部分，请再次调用该操作，并将上一个调用的 `NextToken` 响应值作为 `--starting-token` 的值传递。重复此操作，直到响应中不存在 `NextToken`。  

```
aws resource-explorer-2 list-supported-resource-types \
    --max-items 10  \
    --starting-token eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAxMH0=
```
输出：  

```
{
    "ResourceTypes": [
        {
            "ResourceType": "cloudwatch:metric-stream",
            "Service": "cloudwatch"
        },
        {
            "ResourceType": "dynamodb:table",
            "Service": "dynamodb"
        },
        {
            "ResourceType": "ec2:capacity-reservation",
            "Service": "ec2"
        },
        {
            "ResourceType": "ec2:capacity-reservation-fleet",
            "Service": "ec2"
        },
        {
            "ResourceType": "ec2:client-vpn-endpoint",
            "Service": "ec2"
        },
        {
            "ResourceType": "ec2:customer-gateway",
            "Service": "ec2"
        },
        {
            "ResourceType": "ec2:dedicated-host",
            "Service": "ec2"
        },
        {
            "ResourceType": "ec2:dhcp-options",
            "Service": "ec2"
        },
        {
            "ResourceType": "ec2:egress-only-internet-gateway",
            "Service": "ec2"
        },
        {
            "ResourceType": "ec2:elastic-gpu",
            "Service": "ec2"
        }
    ],
    "NextToken": "eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAyMH0="
}
```
有关索引的更多信息，请参阅《AWS 资源管理器用户指南》中的[检查哪些 AWS 区域开启了资源管理器](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-check.html)**。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListSupportedResourceTypes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/list-supported-resource-types.html)。

### `list-tags-for-resource`
<a name="resource-explorer-2_ListTagsForResource_cli_topic"></a>

以下代码示例演示了如何使用 `list-tags-for-resource`。

**AWS CLI**  
**列出附加到资源管理器视图或索引的标签**  
以下 `list-tags-for-resource` 示例列出了附加到具有指定 ARN 的视图的标签键和值对。您必须从包含资源的 AWS 区域调用操作。  

```
aws resource-explorer-2 list-tags-for-resource \
    --resource-arn arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111
```
输出：  

```
{
    "Tags": {
        "application": "MainCorpApp",
        "department": "1234"
    }
}
```
有关为视图添加标签的更多信息，请参阅《AWS 资源管理器用户**指南》中的[为视图添加标签以实现访问控制](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-tag.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/list-tags-for-resource.html)。

### `list-views`
<a name="resource-explorer-2_ListViews_cli_topic"></a>

以下代码示例演示了如何使用 `list-views`。

**AWS CLI**  
**列出 AWS 区域中可用的资源管理器视图**  
以下 `list-views` 示例列出了您在其中调用操作的区域中可用的所有视图。  

```
aws resource-explorer-2 list-views
```
输出：  

```
{
    "Views": [
        "arn:aws:resource-explorer-2:us-east-1:123456789012:view/EC2-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111",
        "arn:aws:resource-explorer-2:us-east-1:123456789012:view/Default-All-Resources-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222",
        "arn:aws:resource-explorer-2:us-east-1:123456789012:view/Production-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE33333"
    ]
}
```
有关视图的更多信息，请参阅《AWS 资源管理器**用户指南》中的[关于资源管理器视图](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-about.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [ListViews](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/list-views.html)**。

### `search`
<a name="resource-explorer-2_Search_cli_topic"></a>

以下代码示例演示了如何使用 `search`。

**AWS CLI**  
**示例 1：使用默认视图进行搜索**  
以下 `search` 示例显示了与服务关联的指定视图中的所有资源。该搜索使用该区域的默认视图。示例响应中包含一个 `NextToken` 值，该值表示有更多输出可供通过其他调用进行检索。  

```
aws resource-explorer-2 search \
    --query-string "service:iam"
```
输出：  

```
{
    "Count": {
        "Complete": true,
        "TotalResources": 55
    },
    "NextToken": "AG9VOEF1KLEXAMPLEOhJHVwo5chEXAMPLER5XiEpNrgsEXAMPLE...b0CmOFOryHEXAMPLE",
    "Resources": [{
        "Arn": "arn:aws:iam::123456789012:policy/service-role/Some-Policy-For-A-Service-Role",
        "LastReportedAt": "2022-07-21T12:34:42Z",
        "OwningAccountId": "123456789012",
        "Properties": [],
        "Region": "global",
        "ResourceType": "iam:policy",
        "Service": "iam"
    }, {
        "Arn": "arn:aws:iam::123456789012:policy/service-role/Another-Policy-For-A-Service-Role",
        "LastReportedAt": "2022-07-21T12:34:42Z",
        "OwningAccountId": "123456789012",
        "Properties": [],
        "Region": "global",
        "ResourceType": "iam:policy",
        "Service": "iam"
    }, {
       ... TRUNCATED FOR BREVITY ...
    }],
    "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/my-default-view/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111"
}
```
**示例 2：使用指定视图进行搜索**  
以下 `search` 示例搜索显示了指定 AWS 区域中通过指定视图可见的所有资源（“\$1”）。由于视图附带筛选条件，结果仅包含与 Amazon EC2 关联的资源。  

```
aws resource-explorer-2 search \
    -- query-string "*" \
    -- view-arn arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-EC2-view/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222
```
输出：  

```
HTTP/1.1 200 OK
Date: Tue, 01 Nov 2022 20:00:59 GMT
Content-Type: application/json
Content-Length: <PayloadSizeBytes>

    {
        "Count": {
            "Complete": true,
            "TotalResources": 67
        },
        "Resources": [{
            "Arn": "arn:aws:ec2:us-east-1:123456789012:network-acl/acl-1a2b3c4d",
            "LastReportedAt": "2022-07-21T18:52:02Z",
            "OwningAccountId": "123456789012",
            "Properties": [{
                "Data": [{
                    "Key": "Department",
                    "Value": "AppDevelopment"
                }, {
                    "Key": "Environment",
                    "Value": "Production"
                }],
                "LastReportedAt": "2021-11-15T14:48:29Z",
                "Name": "tags"
            }],
            "Region": "us-east-1",
            "ResourceType": "ec2:network-acl",
            "Service": "ec2"
        }, {
            "Arn": "arn:aws:ec2:us-east-1:123456789012:subnet/subnet-1a2b3c4d",
            "LastReportedAt": "2022-07-21T21:22:23Z",
            "OwningAccountId": "123456789012",
            "Properties": [{
                "Data": [{
                    "Key": "Department",
                    "Value": "AppDevelopment"
                }, {
                    "Key": "Environment",
                    "Value": "Production"
                }],
                "LastReportedAt": "2021-07-29T19:02:39Z",
                "Name": "tags"
            }],
            "Region": "us-east-1",
            "ResourceType": "ec2:subnet",
            "Service": "ec2"
        }, {
            "Arn": "arn:aws:ec2:us-east-1:123456789012:dhcp-options/dopt-1a2b3c4d",
            "LastReportedAt": "2022-07-21T06:08:53Z",
            "OwningAccountId": "123456789012",
            "Properties": [{
                "Data": [{
                    "Key": "Department",
                    "Value": "AppDevelopment"
                }, {
                    "Key": "Environment",
                    "Value": "Production"
                }],
                "LastReportedAt": "2021-11-15T15:11:05Z",
                "Name": "tags"
            }],
            "Region": "us-east-1",
            "ResourceType": "ec2:dhcpoptions",
            "Service": "ec2"
        }, {
            ... TRUNCATED FOR BREVITY ...
        }],
        "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-EC2-view/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222"
    }
```
有关更多信息，请参阅《AWS 资源管理器用户指南》中的[使用 AWS 资源管理器搜索资源](https://docs.aws.amazon.com/resource-explorer/latest/userguide/using-search.html)**。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [Search](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/search.html)。

### `tag-resource`
<a name="resource-explorer-2_TagResource_cli_topic"></a>

以下代码示例演示了如何使用 `tag-resource`。

**AWS CLI**  
**为资源管理器视图添加标签**  
以下 `tag-resource` 示例将值为“production”的标签键“environment”添加到具有指定 ARN 的视图中。  

```
aws resource-explorer-2 tag-resource \
    --resource-arn arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-View//EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111 \
    --tags environment=production
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS 资源管理器用户指南》**中的[为视图添加标签以实现访问控制](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-tag.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/tag-resource.html)。

### `untag-resource`
<a name="resource-explorer-2_UntagResource_cli_topic"></a>

以下代码示例演示了如何使用 `untag-resource`。

**AWS CLI**  
**从资源管理器视图中删除标签**  
以下 `untag-resource` 示例从具有指定 ARN 的视图中删除键名为“environment”的所有标签。  

```
aws resource-explorer-2 untag-resource \
    --resource-arn arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-View//EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111 \
    --tag-keys environment
```
此命令不生成任何输出。  
有关更多信息，请参阅《AWS 资源管理器用户指南》**中的[为视图添加标签以实现访问控制](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-tag.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/untag-resource.html)。

### `update-index-type`
<a name="resource-explorer-2_UpdateIndexType_cli_topic"></a>

以下代码示例演示了如何使用 `update-index-type`。

**AWS CLI**  
**更改资源管理器索引的类型**  
以下 `update-index-type` 示例将指定的索引从类型 `local` 转换为类型 `aggregator`，以便能够在该账户的所有 AWS 区域中搜索资源。您必须将请求发送到包含要更新的索引的 AWS 区域。  

```
aws resource-explorer-2 update-index-type \
    --arn arn:aws:resource-explorer-2:us-east-1:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111 \
    --type aggregator \
    --region us-east-1
```
输出：  

```
{
    "Arn":"arn:aws:resource-explorer-2:us-east-1:123456789012:index/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111",
    "LastUpdatedAt":"2022-07-13T18:41:58.799Z",
    "State":"updating",
    "Type":"aggregator"
}
```
有关更改索引类型的更多信息，请参阅《AWS 资源管理器用户指南》**中的[通过创建聚合器索引启用跨区域搜索](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-aggregator-region.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateIndexType](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/update-index-type.html)。

### `update-view`
<a name="resource-explorer-2_UpdateView_cli_topic"></a>

以下代码示例演示了如何使用 `update-view`。

**AWS CLI**  
**示例 1：更新资源管理器视图的 IncludedProperties 字段**  
以下 `update-view` 示例通过将 ``tags`` 添加到可选 ``IncludedProperties`` 来更新指定的视图。运行此操作后，使用此视图的搜索操作将包含有关结果中显示的资源所附标签的信息。  

```
aws resource-explorer-2 update-view \
    --included-properties Name=tags \
    --view-arn arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222
```
输出：  

```
{
    "View": {
        "Filters": {
            "FilterString": ""
        },
        "IncludedProperties": [
            {
                "Name": "tags"
            }
        ],
        "LastUpdatedAt": "2022-07-19T17:41:21.710000+00:00",
        "Owner": "123456789012",
        "Scope": "arn:aws:iam::123456789012:root",
        "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-EC2-Only-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE11111"
    }
}
```
**示例 2：更新附加到视图的筛选条件**  
以下 `update-view` 示例将指定视图更新为使用筛选条件，该筛选条件将结果仅限于与 Amazon EC2 服务关联的资源类型。  

```
aws resource-explorer-2 update-view \
    --filters FilterString="service:ec2" \
    --view-arn arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222
```
输出：  

```
{
    "View": {
    "Filters": {
        "FilterString": "service:ec2"
    },
    "IncludedProperties": [],
    "LastUpdatedAt": "2022-07-19T17:41:21.710000+00:00",
        "Owner": "123456789012",
        "Scope": "arn:aws:iam::123456789012:root",
        "ViewArn": "arn:aws:resource-explorer-2:us-east-1:123456789012:view/My-View/EXAMPLE8-90ab-cdef-fedc-EXAMPLE22222"
    }
}
```
有关视图的更多信息，请参阅《AWS 资源管理器**用户指南》中的[关于资源管理器视图](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-views-about.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateView](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-explorer-2/update-view.html)。