本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
RequestSpotInstances
与 a 一起使用 CLI
以下代码示例演示如何使用 RequestSpotInstances
。
- CLI
-
- AWS CLI
-
请求竞价型实例
此示例命令为指定可用区中的五个实例创建一次性竞价型实例请求。如果您的账户VPC仅支持EC2,则 Amazon EC2 会在指定可用区的默认子网中启动实例。如果您的账户支持 EC2-Classic,则亚马逊EC2将在指定的可用区域中启动 EC2-Classic 中的实例。
命令:
aws ec2 request-spot-instances --spot-price
"0.03"
--instance-count5
--type"one-time"
--launch-specificationfile://specification.json
规格.json:
{ "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroupIds": [ "sg-1a2b3c4d" ], "InstanceType": "m3.medium", "Placement": { "AvailabilityZone": "us-west-2a" }, "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" } }
输出:
{ "SpotInstanceRequests": [ { "Status": { "UpdateTime": "2014-03-25T20:54:21.000Z", "Code": "pending-evaluation", "Message": "Your Spot request has been submitted for review, and is pending evaluation." }, "ProductDescription": "Linux/UNIX", "SpotInstanceRequestId": "sir-df6f405d", "State": "open", "LaunchSpecification": { "Placement": { "AvailabilityZone": "us-west-2a" }, "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupName": "my-security-group", "GroupId": "sg-1a2b3c4d" } ], "Monitoring": { "Enabled": false }, "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" }, "InstanceType": "m3.medium" }, "Type": "one-time", "CreateTime": "2014-03-25T20:54:20.000Z", "SpotPrice": "0.050000" }, ... ] }
此示例命令为指定子网中的五个实例创建一次性竞价型实例请求。Amazon 在指定子网中EC2启动实例。如果VPC为非默认值VPC,则默认情况下实例不会收到公有 IP 地址。
命令:
aws ec2 request-spot-instances --spot-price
"0.050"
--instance-count5
--type"one-time"
--launch-specificationfile://specification.json
规格.json:
{ "ImageId": "ami-1a2b3c4d", "SecurityGroupIds": [ "sg-1a2b3c4d" ], "InstanceType": "m3.medium", "SubnetId": "subnet-1a2b3c4d", "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" } }
输出:
{ "SpotInstanceRequests": [ { "Status": { "UpdateTime": "2014-03-25T22:21:58.000Z", "Code": "pending-evaluation", "Message": "Your Spot request has been submitted for review, and is pending evaluation." }, "ProductDescription": "Linux/UNIX", "SpotInstanceRequestId": "sir-df6f405d", "State": "open", "LaunchSpecification": { "Placement": { "AvailabilityZone": "us-west-2a" } "ImageId": "ami-1a2b3c4d" "SecurityGroups": [ { "GroupName": "my-security-group", "GroupID": "sg-1a2b3c4d" } ] "SubnetId": "subnet-1a2b3c4d", "Monitoring": { "Enabled": false }, "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" }, "InstanceType": "m3.medium", }, "Type": "one-time", "CreateTime": "2014-03-25T22:21:58.000Z", "SpotPrice": "0.050000" }, ... ] }
此示例为您以非VPC默认方式启动的竞价型实例分配公有 IP 地址。请注意,在指定网络接口时,必须使用该网络接口包括子网 ID 和安全组 ID。
命令:
aws ec2 request-spot-instances --spot-price
"0.050"
--instance-count1
--type"one-time"
--launch-specificationfile://specification.json
规格.json:
{ "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:iam::123456789012:instance-profile/my-iam-role" } }
-
有关API详细信息,请参阅AWS CLI 命令参考RequestSpotInstances
中的。
-
- PowerShell
-
- 用于 PowerShell
-
示例 1:此示例请求指定子网中的一次性竞价型实例。请注意,必须为包含指定子网的VPC创建安全组,并且必须使用网络接口通过 ID 进行指定。指定网络接口时,必须使用该网络接口包括子网 ID。
$n = New-Object Amazon.EC2.Model.InstanceNetworkInterfaceSpecification $n.DeviceIndex = 0 $n.SubnetId = "subnet-12345678" $n.Groups.Add("sg-12345678") Request-EC2SpotInstance -InstanceCount 1 -SpotPrice 0.050 -Type one-time ` -IamInstanceProfile_Arn arn:aws:iam::123456789012:instance-profile/my-iam-role ` -LaunchSpecification_ImageId ami-12345678 ` -LaunchSpecification_InstanceType m3.medium ` -LaunchSpecification_NetworkInterface $n
输出:
ActualBlockHourlyPrice : AvailabilityZoneGroup : BlockDurationMinutes : 0 CreateTime : 12/26/2015 7:44:10 AM Fault : InstanceId : LaunchedAvailabilityZone : LaunchGroup : LaunchSpecification : Amazon.EC2.Model.LaunchSpecification ProductDescription : Linux/UNIX SpotInstanceRequestId : sir-12345678 SpotPrice : 0.050000 State : open Status : Amazon.EC2.Model.SpotInstanceStatus Tags : {} Type : one-time
-
有关API详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考RequestSpotInstances中的。
-
有关 AWS SDK开发者指南和代码示例的完整列表,请参阅使用创建 Amazon EC2 资源 AWS SDK。本主题还包括有关入门的信息以及有关先前SDK版本的详细信息。
RequestSpotFleet
ResetImageAttribute