

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 [AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# 使用 的資源總管範例 AWS CLI
<a name="cli_2_resource-explorer-2_code_examples"></a>

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 Resource Explorer 來執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

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

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

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

以下程式碼範例顯示如何使用 `associate-default-view`。

**AWS CLI**  
**將 Resource Explorer 檢視設定為其 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 Resource Explorer 使用者指南*中的[在 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` 範例顯示其 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_2_topic"></a>

以下程式碼範例顯示如何使用 `create-index`。

**AWS CLI**  
**建立索引以開啟 AWS 區域中的資源總管**  
下列`create-index`範例會在呼叫 操作的 AWS 區域中建立本機索引。如果您 AWS 未指定值，CLI AWS 會自動產生隨機`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) 命令，將其轉換為帳戶的彙總工具索引。  
如需詳細資訊，請參閱《[Resource Explorer 使用者指南》中的在 AWS 區域中開啟 Resource Explorer 以編製資源](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-register.html)索引。 *AWS *  
+  如需 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`範例會在指定的 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 區域索引以關閉 區域中的 Resource Explorer**  
下列`delete-index`範例會在 AWS 您提出請求的區域中刪除指定的 Resource Explorer 索引。  

```
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 Resource Explorer 使用者指南》中的在 AWS 區域中關閉](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-deregister.html) Resource Explorer。 *AWS *  
+  如需 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 區域的預設 Resource Explorer 檢視**  
以下內容會`disassociate-default-view`移除您呼叫 操作之 AWS 區域的預設 Resource Explorer 檢視。執行此操作後，區域中的所有搜尋操作都必須明確指定檢視，否則操作會失敗。  

```
aws resource-explorer-2 disassociate-default-view
```
此命令不會產生輸出。  
如需詳細資訊，請參閱 *AWS Resource Explorer 使用者指南*中的[在 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 區域預設檢視的 Resource Explorer 檢視**  
下列`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 Resource Explorer 使用者指南*中的[在 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"
}
```
如需索引的詳細資訊，請參閱《[Resource Explorer 使用者指南》中的檢查已開啟 Resource Explorer AWS](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-check.html)*AWS *的區域。  
+  如需 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**  
**列出 Resource Explorer 具有索引 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"
        }
    ]
}
```
如需索引的詳細資訊，請參閱《[Resource Explorer 使用者指南》中的檢查已開啟 Resource Explorer AWS](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-check.html)*AWS *的區域。  
+  如需 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**  
**列出 Resource Explorer 具有索引 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="
}
```
如需索引的詳細資訊，請參閱《[Resource Explorer 使用者指南》中的檢查已開啟 Resource Explorer AWS](https://docs.aws.amazon.com/resource-explorer/latest/userguide/manage-service-check.html)*AWS *的區域。  
+  如需 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 區域中可用的 Resource Explorer 檢視**  
下列 `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 資源總管使用者指南》中的使用資源總管搜尋資源](https://docs.aws.amazon.com/resource-explorer/latest/userguide/using-search.html)。 *AWS *  
+  如需 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)。