

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

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

以下代码示例向您展示了如何使用 with Resource Explorer 来执行操作和实现常见场景。 AWS Command Line Interface 

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

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

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

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

### `associate-default-view`
<a name="resource-explorer-2_AssociateDefaultView_cli_2_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_2_topic"></a>

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

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

```
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_2_topic"></a>

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

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

```
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_2_topic"></a>

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

**AWS CLI**  
**示例 1：为区域中的索引创建未经过滤的视图 AWS **  
以下`create-view`示例在指定 Region 中创建了一个视图， 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 关联的资源的视图**  
以下内容在 AWS 区域中`create-view`创建了一个视图`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_2_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_2_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_2_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_2_topic"></a>

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

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

```
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_2_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_2_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_2_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_2_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_2_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_2_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_2_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_2_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_2_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_2_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_2_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)*中的。