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
for 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