雲端控制API範例使用 AWS CLI - AWS Command Line Interface

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

雲端控制API範例使用 AWS CLI

下列程式碼範例說明如何使用 Cloud Control 來執行動作和實作常見案例API。 AWS Command Line Interface

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

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

主題

動作

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

AWS CLI

建立資源的步驟

下列create-resource範例會建立名為 AWS:: Kinesis:: Stream 的資源 ResourceExample,其保留期為 168 小時,碎片計數為 3。

aws cloudcontrol create-resource \ --type-name AWS::Kinesis::Stream \ --desired-state "{\"Name\": \"ResourceExample\",\"RetentionPeriodHours\":168, \"ShardCount\":3}"

輸出:

{ "ProgressEvent": { "EventTime": 1632506656.706, "TypeName": "AWS::Kinesis::Stream", "OperationStatus": "IN_PROGRESS", "Operation": "CREATE", "Identifier": "ResourceExample", "RequestToken": "20999d87-e304-4725-ad84-832dcbfd7fc5" } }

如需詳細資訊,請參Cloud Control API 使用者指南中的建立資源

  • 如需詳API細資訊,請參閱AWS CLI 指令參考CreateResource中的。

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

AWS CLI

刪除資源的步驟

下列delete-resource範例會 ResourceExample 從您的 AWS帳戶刪除具有識別碼的:: Kinesis:: Stream 資源。 AWS

aws cloudcontrol delete-resource \ --type-name AWS::Kinesis::Stream \ --identifier ResourceExample

輸出:

{ "ProgressEvent": { "TypeName": "AWS::Kinesis::Stream", "Identifier": "ResourceExample", "RequestToken": "e48f26ff-d0f9-4ab8-a878-120db1edf111", "Operation": "DELETE", "OperationStatus": "IN_PROGRESS", "EventTime": 1632950300.14 } }

如需詳細資訊,請參閱雲端控制API使用指南中的刪除資源

  • 如需詳API細資訊,請參閱AWS CLI 指令參考DeleteResource中的。

下列程式碼範例會示範如何使用get-resource-request-status

AWS CLI

若要取得資源要求的狀態資訊

下列get-resource-request-status範例會傳回有關指定資源要求的狀態資訊。

aws cloudcontrol get-resource-request-status \ --request-token "e1a6b86e-46bd-41ac-bfba-001234567890"

輸出:

{ "ProgressEvent": { "TypeName": "AWS::Kinesis::Stream", "Identifier": "Demo", "RequestToken": "e1a6b86e-46bd-41ac-bfba-001234567890", "Operation": "CREATE", "OperationStatus": "FAILED", "EventTime": 1632950268.481, "StatusMessage": "Resource of type 'AWS::Kinesis::Stream' with identifier 'Demo' already exists.", "ErrorCode": "AlreadyExists" } }

如需詳細資訊,請參閱 Cloud Control API 使用者指南中的管理資源作業要求

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

AWS CLI

若要取得資源的目前狀態

下列get-resource範例會傳回名為:: Kinesis: AWS: 串流資源的目前狀態。 ResourceExample

aws cloudcontrol get-resource \ --type-name AWS::Kinesis::Stream \ --identifier ResourceExample

輸出:

{ "TypeName": "AWS::Kinesis::Stream", "ResourceDescription": { "Identifier": "ResourceExample", "Properties": "{\"Arn\":\"arn:aws:kinesis:us-west-2:099908667365:stream/ResourceExample\",\"RetentionPeriodHours\":168,\"Name\":\"ResourceExample\",\"ShardCount\":3}" } }

如需詳細資訊,請參Cloud Control API 使用者指南中的讀取資源的目前狀態

  • 如需詳API細資訊,請參閱AWS CLI 指令參考GetResource中的。

下列程式碼範例會示範如何使用list-resource-requests

AWS CLI

若要列出使用中資源作業請求

下列list-resource-requests範例會列出您 AWS 帳號中失敗的資源要求CREATE和UPDATE作業。

aws cloudcontrol list-resource-requests \ --resource-request-status-filter Operations=CREATE,OperationStatuses=FAILED

輸出:

{ "ResourceRequestStatusSummaries": [ { "TypeName": "AWS::Kinesis::Stream", "Identifier": "Demo", "RequestToken": "e1a6b86e-46bd-41ac-bfba-633abcdfdbd7", "Operation": "CREATE", "OperationStatus": "FAILED", "EventTime": 1632950268.481, "StatusMessage": "Resource of type 'AWS::Kinesis::Stream' with identifier 'Demo' already exists.", "ErrorCode": "AlreadyExists" } ] }

如需詳細資訊,請參閱 Cloud Control API 使用者指南中的管理資源作業要求

下列程式碼範例會示範如何使用list-resources

AWS CLI

列出給定類型的資源

下列list-resources範例列出您帳戶中佈建的 AWS:: Kinesis:: 串流資源。 AWS

aws cloudcontrol list-resources \ --type-name AWS::Kinesis::Stream

輸出:

{ "TypeName": "AWS::Kinesis::Stream", "ResourceDescriptions": [ { "Identifier": "MyKinesisStream", "Properties": "{\"Name\":\"MyKinesisStream\"}" }, { "Identifier": "AnotherStream", "Properties": "{\"Name\":\"AnotherStream\"}" } ] }

如需詳細資訊,請參閱雲端控制API使用指南中的探查資源

  • 如需詳API細資訊,請參閱AWS CLI 指令參考ListResources中的。

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

AWS CLI

更新現有資源的屬性的步驟

下列update-resource範例會更新名稱為 ExampleLogGroup 90 天的 AWS:: Logs:: LogGroup 資源的保留原則。

aws cloudcontrol update-resource \ --type-name AWS::Logs::LogGroup \ --identifier ExampleLogGroup \ --patch-document "[{\"op\":\"replace\",\"path\":\"/RetentionInDays\",\"value\":90}]"

輸出:

{ "ProgressEvent": { "EventTime": "2021-08-09T18:17:15.219Z", "TypeName": "AWS::Logs::LogGroup", "OperationStatus": "IN_PROGRESS", "Operation": "UPDATE", "Identifier": "ExampleLogGroup", "RequestToken": "5f40c577-3534-4b20-9599-0b0123456789" } }

如需詳細資訊,請參Cloud Control API 使用者指南中的更新資源

  • 如需詳API細資訊,請參閱AWS CLI 指令參考UpdateResource中的。