def request_spot_instances(
price=0.01, zone='us-west-2a', inst_type=INSTANCE_TYPE,
inst_id="ami-9abea4fb"):
' request spot instances '
# ami-9abea4fb - ubuntu-trusty-14.04-amd64-server
launch_specification = '''
{{
"ImageId": "{}",
"KeyName": "ubuntu_trusty",
"SecurityGroupIds": [ "sg-94a671f3" ],
"InstanceType": "{}"
}}
'''.format(inst_id, inst_type)
ls_encode = launch_specification.replace('\n', '')
ls_encode = ls_encode.replace('"', '\\"')
aws_cmd = 'aws ec2 request-spot-instances --spot-price "{}" --instance-count 1 --type "one-time" --availability-zone-group {} --launch-specification "{}"'
aws_cmd = aws_cmd.format(price, zone, ls_encode)
jq_cmd = 'jq -c -C "."'
with hide("running"):
local('|'.join([aws_cmd, jq_cmd]))
评论列表
文章目录