CreateCapacityReservation 搭配 使用 CLI - AWS SDK 程式碼範例

文件範例儲存庫中有更多 AWS SDK可用的範例。 AWS SDK GitHub

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

CreateCapacityReservation 搭配 使用 CLI

下列程式碼範例示範如何使用 CreateCapacityReservation

CLI
AWS CLI

範例 1:建立容量預留

下列create-capacity-reservation範例會在eu-west-1a可用區域中建立容量保留,您可以在其中啟動三個執行 Linux/Unix 作業系統的t2.medium執行個體。根據預設,容量保留會建立為開啟的執行個體比對條件,且不支援暫時儲存,且會保持作用中狀態,直到您手動取消為止。

aws ec2 create-capacity-reservation \ --availability-zone eu-west-1a \ --instance-type t2.medium \ --instance-platform Linux/UNIX \ --instance-count 3

輸出:

{ "CapacityReservation": { "CapacityReservationId": "cr-1234abcd56EXAMPLE ", "EndDateType": "unlimited", "AvailabilityZone": "eu-west-1a", "InstanceMatchCriteria": "open", "EphemeralStorage": false, "CreateDate": "2019-08-16T09:27:35.000Z", "AvailableInstanceCount": 3, "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 3, "State": "active", "Tenancy": "default", "EbsOptimized": false, "InstanceType": "t2.medium" } }

範例 2:建立在指定日期/時間自動結束的容量保留

下列create-capacity-reservation範例會在eu-west-1a可用區域中建立容量保留,您可以在其中啟動三個執行 Linux/Unix 作業系統的m5.large執行個體。此容量保留會在 08/31/2019 23:59:59 自動結束。

aws ec2 create-capacity-reservation \ --availability-zone eu-west-1a \ --instance-type m5.large \ --instance-platform Linux/UNIX \ --instance-count 3 \ --end-date-type limited \ --end-date 2019-08-31T23:59:59Z

輸出:

{ "CapacityReservation": { "CapacityReservationId": "cr-1234abcd56EXAMPLE ", "EndDateType": "limited", "AvailabilityZone": "eu-west-1a", "EndDate": "2019-08-31T23:59:59.000Z", "InstanceMatchCriteria": "open", "EphemeralStorage": false, "CreateDate": "2019-08-16T10:15:53.000Z", "AvailableInstanceCount": 3, "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 3, "State": "active", "Tenancy": "default", "EbsOptimized": false, "InstanceType": "m5.large" } }

範例 3:建立僅接受目標執行個體啟動的容量保留

下列create-capacity-reservation範例會建立僅接受目標執行個體啟動的容量保留。

aws ec2 create-capacity-reservation \ --availability-zone eu-west-1a \ --instance-type m5.large \ --instance-platform Linux/UNIX \ --instance-count 3 \ --instance-match-criteria targeted

輸出:

{ "CapacityReservation": { "CapacityReservationId": "cr-1234abcd56EXAMPLE ", "EndDateType": "unlimited", "AvailabilityZone": "eu-west-1a", "InstanceMatchCriteria": "targeted", "EphemeralStorage": false, "CreateDate": "2019-08-16T10:21:57.000Z", "AvailableInstanceCount": 3, "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 3, "State": "active", "Tenancy": "default", "EbsOptimized": false, "InstanceType": "m5.large" } }

如需詳細資訊,請參閱 Amazon Elastic Compute Cloud Linux 執行個體使用者指南 中的建立容量保留

PowerShell
適用於 的工具 PowerShell

範例 1:此範例會建立具有指定屬性的新容量保留

Add-EC2CapacityReservation -InstanceType m4.xlarge -InstanceCount 2 -AvailabilityZone eu-west-1b -EbsOptimized True -InstancePlatform Windows

輸出:

AvailabilityZone : eu-west-1b AvailableInstanceCount : 2 CapacityReservationId : cr-0c1f2345db6f7cdba CreateDate : 3/28/2019 9:29:41 AM EbsOptimized : True EndDate : 1/1/0001 12:00:00 AM EndDateType : unlimited EphemeralStorage : False InstanceMatchCriteria : open InstancePlatform : Windows InstanceType : m4.xlarge State : active Tags : {} Tenancy : default TotalInstanceCount : 2