Boto3:如何从Spot Request创建实例ID?

时间:2018-06-09 06:26:37

标签: python amazon-web-services boto3

发出现场请求并等待现场请求得到满足似乎有效。

接下来,我如何获取为了检查例如创建的ec2实例id /对象IP地址等?

这是我到目前为止的代码:

def create_spot_instance():
    print("Send Spot Request")
    ec2_client = boto3.client('ec2')
    res = ec2_client.request_spot_instances(
        ...
    )
    request_id = res['SpotInstanceRequests'][0]['SpotInstanceRequestId']
    print("Wait for request to be fulfilled...")
    waiter = ec2_client.get_waiter('spot_instance_request_fulfilled')
    waiter.wait(SpotInstanceRequestIds=[request_id])
    print("Wait for ec2 instance to boot up...")
    # TODO: get instance id the spot instance created
    # TODO: wait until spot instance is booted up
    # TODO: return object of ec2 instance

1 个答案:

答案 0 :(得分:1)

describe_spot_instance_requests应该为spot创建的实例ID提供。

参见:https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.describe_spot_instance_requests