gpt4 book ai didi

python - 使用 ec2 python API boto,如何从 SpotInstanceRequest 获取 spot instance_id?

转载 作者:太空狗 更新时间:2023-10-30 01:02:54 26 4
gpt4 key购买 nike

当使用 boto 时,Amazon aws python API。

ec2_connection.request_spot_instances(...)
# This will return an ResultSet of SpotInstanceRequest

如何从 SpotInstanceRequest 获取 instance_ids?

更新:我是这样做的,经过大量的尝试和谷歌搜索,希望对您有所帮助:

ec2_connection.get_all_spot_instance_requests(request_ids=[my_spot_request_id, ])

这将返回更新的SpotInstanceRequest,当实例准备就绪时,我们可以从中获取*instance_id*。

最佳答案

我做了类似的事情:定期检查以查看是否返回了 spot 实例请求 idec2_connection.request_spot_instances(...) 与结果中的实例匹配conn.get_all_spot_instance_requests(...) :

conn = boto.ec2.connect_to_region(region_name=region_name, aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
req = conn.request_spot_instances(price=MAX_SPOT_BID,instance_type=instance_type,image_id=AMI_ID,availability_zone_group=region_name,key_name=KEY_PAIR_PEM[:-4],security_groups=security_groups)
job_instance_id = None
while job_instance_id == None:
print "checking job instance id for this spot request"
job_sir_id = req[0].id # spot instance request = sir, job_ is the relevant aws item for this job
reqs = conn.get_all_spot_instance_requests()
for sir in reqs:
if sir.id == job_sir_id:
job_instance_id = sir.instance_id
print "job instance id: " + str(job_instance_id)
break
time.sleep(SPINUP_WAIT_TIME)

关于python - 使用 ec2 python API boto,如何从 SpotInstanceRequest 获取 spot instance_id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12801966/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com