CreateCapacityReservation与 a 一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

CreateCapacityReservation与 a 一起使用 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实例。此容量预留将于 2019 年 8 月 31 日 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" } }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的创建容量预留

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