Amazon Elastic Compute Cloud
Windows 实例用户指南
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

Spot 队列示例配置

下列示例显示了可与 request-spot-fleet 命令结合使用以创建 Spot 队列请求的启动配置。有关更多信息,请参阅 创建 Spot 队列请求

示例 1:使用区域中价格最低的可用区或子网启动 Spot 实例

以下示例指定一个没有可用区或子网的启动说明。如果您的账户仅支持 EC2-VPC,则 Spot 队列将在具有默认子网的价格最低的可用区中启动实例。如果您的账户支持 EC2-Classic,则 Spot 队列将在价格最低的可用区的 EC2-Classic 中启动实例。您支付的价格将不会超过为请求指定的现货价格。

Copy
{ "SpotPrice": "0.07", "TargetCapacity": 20, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "m3.medium", "IamInstanceProfile": { "Arn": "arn:aws-cn:iam::123456789012:instance-profile/my-iam-role" } } ] }

示例 2:使用指定列表中价格最低的可用区或子网启动 Spot 实例

以下示例指定具有的可用区或子网不同但实例类型和 AMI 相同的两种启动说明。

可用区

如果您的账户仅支持 EC2-VPC,则 Spot 队列将在您指定的价格最低的可用区的默认子网中启动实例。如果您的账户支持 EC2-Classic,则 Spot 队列将在您指定的价格最低的可用区中启动实例。

Copy
{ "SpotPrice": "0.07", "TargetCapacity": 20, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "m3.medium", "Placement": { "AvailabilityZone": "us-west-2a, us-west-2b" }, "IamInstanceProfile": { "Arn": "arn:aws-cn:iam::123456789012:instance-profile/my-iam-role" } } ] }

Subnets

您可以指定默认子网或非默认子网,并且非默认子网可来自默认 VPC 或非默认 VPC。竞价服务会在位于价格最低的可用区的子网中启动实例。

您无法在 Spot 队列请求中指定来自相同可用区的不同子网。

Copy
{ "SpotPrice": "0.07", "TargetCapacity": 20, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "m3.medium", "SubnetId": "subnet-a61dafcf, subnet-65ea5f08", "IamInstanceProfile": { "Arn": "arn:aws-cn:iam::123456789012:instance-profile/my-iam-role" } } ] }

如果在默认 VPC 中启动实例,则实例在默认情况下会收到一个公有 IPv4 地址。如果在非默认 VPC 中启动实例,则实例在默认情况下不会收到一个公有 IPv4 地址。在启动说明中使用网络接口来将一个公有 IPv4 地址分配给在非默认 VPC 中启动的实例。指定网络接口时,您必须包括使用网络接口的子网 ID 和安全组 ID。

Copy
... { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "InstanceType": "m3.medium", "NetworkInterfaces": [ { "DeviceIndex": 0, "SubnetId": "subnet-1a2b3c4d", "Groups": [ "sg-1a2b3c4d" ], "AssociatePublicIpAddress": true } ], "IamInstanceProfile": { "Arn": "arn:aws-cn:iam::880185128111:instance-profile/my-iam-role" } } ...

示例 3:使用指定列表中价格最低的实例类型启动 Spot 实例

以下示例指定实例类型不同、但 AMI 和可用区或子网相同的两种启动配置。 Spot 队列启动使用价格最低的指定实例类型的实例。

可用区

Copy
{ "SpotPrice": "1.00", "TargetCapacity": 20, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "cc2.8xlarge", "Placement": { "AvailabilityZone": "us-west-2b" } }, { "ImageId": "ami-1a2b3c4d", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "r3.8xlarge", "Placement": { "AvailabilityZone": "us-west-2b" } } ] }

子网

Copy
{ "SpotPrice": "1.00", "TargetCapacity": 20, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "cc2.8xlarge", "SubnetId": "subnet-1a2b3c4d" }, { "ImageId": "ami-1a2b3c4d", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "r3.8xlarge", "SubnetId": "subnet-1a2b3c4d" } ] }

示例 4. 覆盖请求的现货价格

通过为单个启动说明指定现货价格的功能,您可对出价过程进行更多控制。以下示例使用三个启动说明中的两个启动说明单独使用的现货价格来覆盖请求的现货价格。请求的现货价格用于未单独指定现货价格的任何启动说明。 Spot 队列启动使用价格最低的实例类型的实例。

可用区

Copy
{ "SpotPrice": "1.00", "TargetCapacity": 30, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.2xlarge", "Placement": { "AvailabilityZone": "us-west-2b" }, "SpotPrice": "0.10" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.4xlarge", "Placement": { "AvailabilityZone": "us-west-2b" }, "SpotPrice": "0.20" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.8xlarge", "Placement": { "AvailabilityZone": "us-west-2b" } } ] }

子网

Copy
{ "SpotPrice": "1.00", "TargetCapacity": 30, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.2xlarge", "SubnetId": "subnet-1a2b3c4d", "SpotPrice": "0.10" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.4xlarge", "SubnetId": "subnet-1a2b3c4d", "SpotPrice": "0.20" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.8xlarge", "SubnetId": "subnet-1a2b3c4d" } ] }

示例 5:使用多样化分配策略启动 Spot 队列

以下示例使用 diversified 分配策略。启动说明具有不同的实例类型,但具有相同的 AMI 和可用区或子网。 Spot 队列在 3 个启动说明间分配 30 个实例,每种类型 10 个实例。有关更多信息,请参阅 Spot 队列分配策略

可用区

Copy
{ "SpotPrice": "0.70", "TargetCapacity": 30, "AllocationStrategy": "diversified", "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "InstanceType": "c4.2xlarge", "Placement": { "AvailabilityZone": "us-west-2b" } }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "m3.2xlarge", "Placement": { "AvailabilityZone": "us-west-2b" } }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "r3.2xlarge", "Placement": { "AvailabilityZone": "us-west-2b" } } ] }

子网

Copy
{ "SpotPrice": "0.70", "TargetCapacity": 30, "AllocationStrategy": "diversified", "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "InstanceType": "c4.2xlarge", "SubnetId": "subnet-1a2b3c4d" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "m3.2xlarge", "SubnetId": "subnet-1a2b3c4d" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "r3.2xlarge", "SubnetId": "subnet-1a2b3c4d" } ] }

示例 6:使用实例权重启动 Spot 队列

以下示例使用实例权重,这意味着出价是每单位小时出价而不是每实例小时出价。每个启动配置列出不同的实例类型和不同的权重。 Spot 队列选择每单位小时价格最低的实例类型。 Spot 队列通过将目标容量除以实例权重来计算要启动的 Spot 实例数。如果结果不是整数,则 Spot 队列会将其向上舍入到下一个整数,以便队列的大小不低于其目标容量。

如果 r3.2xlarge 出价成功,竞价将预置 4 个这类实例。将 20 除以 6 可得到总共 3.33 个实例,然后向上舍入为 4 个实例。

如果 c3.xlarge 出价成功,竞价将预置 7 个这类实例。将 20 除以 3 可得到总共 6.66 个实例,然后向上舍入为 7 个实例。

有关更多信息,请参阅 Spot 队列实例权重

可用区

Copy
{ "SpotPrice": "0.70", "TargetCapacity": 20, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "InstanceType": "r3.2xlarge", "Placement": { "AvailabilityZone": "us-west-2b" }, "WeightedCapacity": 6 }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.xlarge", "Placement": { "AvailabilityZone": "us-west-2b" }, "WeightedCapacity": 3 } ] }

子网

Copy
{ "SpotPrice": "0.70", "TargetCapacity": 20, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "InstanceType": "r3.2xlarge", "SubnetId": "subnet-1a2b3c4d", "WeightedCapacity": 6 }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.xlarge", "SubnetId": "subnet-1a2b3c4d", "WeightedCapacity": 3 } ] }

优先级

您也可以使用实例权重为可用区或子网指定优先级。例如,以下启动说明几乎完全相同,只是指定了不同的子网和权重。 Spot 队列将查找具有最高 WeightedCapacity 值的说明,并尝试在相应子网中价格最低的 Spot 实例池中预置请求。第二个启动说明不包含权重,因此其默认为 1。

Copy
{ "SpotPrice": "0.42", "TargetCapacity": 40, "IamFleetRole": "arn:aws-cn:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.2xlarge", "SubnetId": "subnet-482e4972", "WeightedCapacity": 2 }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "c3.2xlarge", "SubnetId": "subnet-bb3337d" } ] }