spot instance with run_instances.

pull/30/head
Richard Liu 6 years ago
parent 39fd36e224
commit 9661f0b4f0
  1. 20
      aws-experiment-launch/create_and_deploy.py

@ -87,17 +87,22 @@ def create_instances(config, ec2_client, region_number, number_of_instances):
}, },
] ]
}, },
] ],
# We can also request spot instances this way but this way will block the
# process until spot requests are fulfilled, otherwise it will throw exception
# after 4 failed re-try.
# InstanceMarketOptions= {
# 'MarketType': 'spot',
# 'SpotOptions': {
# 'SpotInstanceType': 'one-time',
# 'BlockDurationMinutes': 60,
# }
# }
) )
return response return response
def request_spots(config, ec2_client, region_number, number_of_instances): def request_spots(config, ec2_client, region_number, number_of_instances):
placement_group = region_number + "-" + PLACEMENT_GROUP
response = ec2_client.create_placement_group(
GroupName=placement_group,
Strategy='spread'
)
response = ec2_client.request_spot_instances( response = ec2_client.request_spot_instances(
# DryRun=True, # DryRun=True,
BlockDurationMinutes=60, BlockDurationMinutes=60,
@ -112,8 +117,7 @@ def request_spots(config, ec2_client, region_number, number_of_instances):
'InstanceType': INSTANCE_TYPE, 'InstanceType': INSTANCE_TYPE,
'KeyName': config[region_number][REGION_KEY], 'KeyName': config[region_number][REGION_KEY],
'Placement': { 'Placement': {
'AvailabilityZone': get_one_availability_zone(ec2_client), 'AvailabilityZone': get_one_availability_zone(ec2_client)
'GroupName': placement_group
} }
} }
) )

Loading…
Cancel
Save