@xtccc
2017-09-12T23:50:47.000000Z
字数 2242
阅读 1927
AWS
目录:
通过AWS Client申请。
$ aws ec2 request-spot-fleet --spot-fleet-request-config file://test.json --region us-west-2
返回
{
"SpotFleetRequestId": "sfr-6f5f82e5-3d2c-4422-81c7-xxxxx"
}
其中,test.json是关于Fleet Request的配置文件,一个样例为:
{
"IamFleetRole": "arn:aws:iam::xxxxx:role/aws-ec2-spot-fleet-tagging-role",
"AllocationStrategy": "lowestPrice",
"TargetCapacity": 2,
"SpotPrice": "0.1225",
"ValidFrom": "2017-09-11T09:50:00Z",
"ValidUntil": "2018-09-11T09:50:00Z",
"TerminateInstancesWithExpiration": true,
"Type": "maintain",
"LaunchSpecifications": [
{
"ImageId": "ami-xxxxxx",
"InstanceType": "m1.xlarge",
"SubnetId": "subnet-xxxxx",
"KeyName": "akka_oregon",
"WeightedCapacity": 4,
"SpotPrice": "0.0875",
"IamInstanceProfile": {
"Arn": "arn:aws:iam::xxxxxxxxx:instance-profile/akka-web"
},
"SecurityGroups": [
{
"GroupId": "sg-xxxxx"
}
],
"UserData": "bWtkaXIgdGFv",
"TagSpecifications": [
{
"ResourceType": "instance",
"Tags": [
{
"Key": "Name",
"Value": "XiaoTao"
}
]
}
]
},
{
"ImageId": "ami-yyyyy",
"InstanceType": "m2.4xlarge",
"SubnetId": "subnet-yyyyy",
"KeyName": "akka_oregon",
"WeightedCapacity": 8,
"SpotPrice": "0.1225",
"IamInstanceProfile": {
"Arn": "arn:aws:iam::yyyyyyyy:instance-profile/akka-web"
},
"SecurityGroups": [
{
"GroupId": "sg-yyyyyy"
}
],
"UserData": "bWtkaXIgdGFv",
"TagSpecifications": [
{
"ResourceType": "instance",
"Tags": [
{
"Key": "Name",
"Value": "XiaoTao"
}
]
}
]
}
]
}
$ aws ec2 describe-spot-fleet-instances --spot-fleet-request-id sfr-6f5f82e5-3d2c-4422-xxxxx --region us-west-2
返回
{
"ActiveInstances": [
{
"InstanceId": "i-xxxxx",
"InstanceType": "m1.small",
"SpotInstanceRequestId": "sir-xxxx"
},
{
"InstanceId": "i-yyyyy",
"InstanceType": "m1.small",
"SpotInstanceRequestId": "sir-yyyyy"
}
],
"SpotFleetRequestId": "sfr-6f5f82e5-3d2c-4422-xxxxx"
}
$ aws ec2 cancel-spot-fleet-requests --spot-fleet-request-ids sfr-6f5f82e5-3d2c-4422-81c7-xxxx --terminate-instances --region us-west-2
返回
{
"SuccessfulFleetRequests": [
{
"PreviousSpotFleetRequestState": "active",
"CurrentSpotFleetRequestState": "cancelled_terminating",
"SpotFleetRequestId": "sfr-6f5f82e5-3d2c-4422-81c7-xxxx"
}
],
"UnsuccessfulFleetRequests": []
}
注意,必须加上--terminate-instances
,否则只是cancel spot fleet request, 正在运行的spot fleet instances不会被terminate。