使用 的資源總管範例 AWS CLI - AWS Command Line Interface

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

使用 的資源總管範例 AWS CLI

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

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

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

主題

動作

下列程式碼範例示範如何使用 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 區域中設定預設檢視

下列程式碼範例示範如何使用 batch-get-view

AWS CLI

擷取多個 Resource Explorer 檢視的詳細資訊

下列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": [] }

如需檢視的詳細資訊,請參閱 Resource Explorer 使用者指南中的關於 AWS Resource Explorer 檢視。

  • 如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 BatchGetView

下列程式碼範例示範如何使用 create-index

AWS CLI

建立索引以開啟 AWS 區域中的 Resource Explorer

下列create-index範例會在呼叫 操作的 AWS 區域中建立本機索引。CLI AWS 會自動產生隨機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 命令,將其轉換為帳戶的彙總器索引。

如需詳細資訊,請參閱《Resource Explorer 使用者指南》中的在 AWS 區域中開啟 Resource Explorer 以為您的資源編製索引AWS

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateIndex

下列程式碼範例示範如何使用 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 Resource Explorer 使用者指南中的建立要搜尋的檢視

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 CreateView

下列程式碼範例示範如何使用 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。 AWS

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteIndex

下列程式碼範例示範如何使用 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 使用者指南中的刪除檢視

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteView

下列程式碼範例示範如何使用 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 區域中設定預設檢視

下列程式碼範例示範如何使用 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 區域中設定預設檢視

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetDefaultView

下列程式碼範例示範如何使用 get-index

AWS CLI

範例 1:擷取 Resource Explorer 彙總器索引的詳細資訊

下列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:擷取 Resource Explorer 本機索引的詳細資訊

下列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 使用者指南》中的檢查哪些 AWS 區域已開啟 Resource Explorer。 AWS

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetIndex

下列程式碼範例示範如何使用 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" } }

如需檢視的詳細資訊,請參閱 Resource Explorer 使用者指南中的關於 AWS Resource Explorer 檢視。

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetView

下列程式碼範例示範如何使用 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" } ] }

如需索引的詳細資訊,請參閱 Resource Explorer 使用者指南中的檢查哪些 AWS 區域已開啟 Resource Explorer。 AWS

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListIndexes

下列程式碼範例示範如何使用 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 使用者指南中的檢查哪些 AWS 區域已開啟 Resource Explorer。 AWS

下列程式碼範例示範如何使用 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 使用者指南中的標記存取控制的檢視

下列程式碼範例示範如何使用 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" ] }

如需檢視的詳細資訊,請參閱 Resource Explorer 使用者指南中的關於 AWS Resource Explorer 檢視。

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 ListViews

下列程式碼範例示範如何使用 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 區域中可透過指定檢視看見的所有資源 ("*")。結果僅包含與 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 使用者指南》中的使用 Resource Explorer 搜尋資源AWS

  • 如需 API 詳細資訊,請參閱在AWS CLI 命令參考搜尋

下列程式碼範例示範如何使用 tag-resource

AWS CLI

標記 Resource Explorer 檢視

下列tag-resource範例會將值為「生產」的標籤金鑰「環境」新增至具有指定 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 Resource Explorer 使用者指南中的標記存取控制的檢視

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 TagResource

下列程式碼範例示範如何使用 untag-resource

AWS CLI

從 Resource Explorer 檢視中移除標籤

下列untag-resource範例會從具有指定 ARN 的檢視中移除具有金鑰名稱「環境」的任何標籤。

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 使用者指南中的標記存取控制的檢視

  • 如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 UntagResource

下列程式碼範例示範如何使用 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 使用者指南》中的透過建立彙總器索引開啟跨區域搜尋

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 UpdateIndexType

下列程式碼範例示範如何使用 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" } }

如需檢視的詳細資訊,請參閱 Resource Explorer 使用者指南中的關於 AWS Resource Explorer 檢視。

  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 UpdateView