

# Resource Explorer examples using AWS CLI
<a name="cli_resource-explorer-2_code_examples"></a>

次のコード例は、Resource Explorer で 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**  
**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_topic"></a>

次のコード例は、`batch-get-view` を使用する方法を示しています。

**AWS CLI**  
**複数の Resource Explorer ビューの詳細を取得するには**  
次の `batch-get-view` の例では、ARN で指定された 2 つのビューの詳細を表示します。スペースを使用して、--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 Resource Explorer ユーザーガイド*」の「[Resource Explorer ビューについて](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 リージョン内の Resource Explorer をオンにするには**  
次の `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 Resource Explorer ユーザーガイド*」の「[AWS リージョンで Resource Explorer を有効にしてリソースをインデックス化する](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 リージョンにビューを作成し、フィルタリングなしでリージョン内のすべての結果を返します。ビューには、返された結果のオプションのタグフィールドが含まれます。このビューはアグリゲータインデックスを含むリージョンで作成されるため、Resource Explorer インデックスを含むアカウント内のすべてのリージョンの結果を含めることができます。  

```
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` では、Amazon EC2 サービスに関連付けられている AWS リージョン `us-east-1` 内のリソースのみを返すビューをリージョンに作成します。ビューには、返された結果のオプションの `Tags` フィールドが含まれます。このビューはアグリゲータインデックスを含むリージョンで作成されるため、Resource Explorer インデックスを含むアカウント内のすべてのリージョンの結果を含めることができます。  

```
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 Resource Explorer ユーザーガイド*」の「[検索に使用するビューの作成](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 リージョンの 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 リージョンで Resource Explorer をオフにする](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**  
**Resource Explorer ビューを削除するには**  
次の `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 Resource Explorer ユーザーガイド*」の「[ビューの削除](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 リージョンのデフォルトの 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_topic"></a>

次のコード例は、`get-default-view` を使用する方法を示しています。

**AWS CLI**  
**AWS リージョンのデフォルトビューである Resource Explorer ビューを取得するには**  
次の `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 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_topic"></a>

次のコード例は、`get-index` を使用する方法を示しています。

**AWS CLI**  
**例 1: Resource Explorer アグリゲータインデックスの詳細を取得するには**  
以下の `get-index` 例は、指定された AWS リージョンにある Resource Explorer インデックスの詳細を表示します。指定されたリージョンにはアカウントのアグリゲータインデックスが含まれているため、出力には、このリージョンのインデックスにデータをレプリケートするリージョンが一覧表示されます。  

```
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: Resource Explorer ローカルインデックスの詳細を取得するには**  
以下の `get-index` 例は、指定された AWS リージョンにある Resource Explorer インデックスの詳細を表示します。指定されたリージョンにはローカルインデックスが含まれているため、出力には、このリージョンのインデックスからデータをレプリケートするリージョンが一覧表示されます。  

```
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 Resource Explorer ユーザーガイド*」の「[Resource Explorer が有効になっている 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**  
**Resource Explorer ビューの詳細を取得するには**  
次の `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 Resource Explorer ユーザーガイド*」の「[Resource Explorer ビューについて](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**  
**Resource Explorer にインデックスがある AWS リージョンを一覧表示するには**  
次の `list-indexes` の例では、Resource Explorer にインデックスがあるすべてのリージョンのインデックスを一覧表示します。レスポンスは、各インデックスのタイプ、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 Resource Explorer ユーザーガイド*」の「[Resource Explorer が有効になっている 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**  
**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="
}
```
インデックスの詳細については、「*AWS Resource Explorer ユーザーガイド*」の「[Resource Explorer が有効になっている 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**  
**Resource Explorer ビューまたはインデックスにアタッチされたタグを一覧表示するには**  
次の `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 Resource Explorer ユーザーガイド*」の「[アクセス制御のビューのタグ付け](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 リージョンで使用できる 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 Resource Explorer ユーザーガイド*」の「[Resource Explorer ビューについて](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 Resource Explorer ユーザーガイド*」の「[AWS Resource Explorer を使用してリソースを検索する](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**  
**Resource Explorer ビューにタグを付けるには**  
次の `tag-resource` の例では、指定された ARN を持つビューに、値「production」を持つタグキー「environment」を追加します。  

```
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 Resource Explorer ユーザーガイド*」の「[アクセス制御のビューのタグ付け](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**  
**Resource Explorer ビューからタグを削除するには**  
次の `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 Resource Explorer ユーザーガイド*」の「[アクセス制御のビューのタグ付け](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**  
**Resource Explorer インデックスのタイプを変更するには**  
次の `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 Resource Explorer ユーザーガイド」の「[アグリゲータインデックスを作成してクロスリージョン検索をオンにする](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: Resource Explorer ビューの 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 Resource Explorer ユーザーガイド*」の「[Resource Explorer ビューについて](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)」を参照してください。