Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Boto3:如何获取从Spot请求创建的实例ID?_Python_Amazon Web Services_Boto3 - Fatal编程技术网

Python Boto3:如何获取从Spot请求创建的实例ID?

Python Boto3:如何获取从Spot请求创建的实例ID?,python,amazon-web-services,boto3,Python,Amazon Web Services,Boto3,发出即时请求并等待即时请求得到满足似乎是可行的 接下来,我如何获取为检查例如IP地址等而创建的ec2实例id/对象 这就是我目前掌握的代码: def create_spot_instance(): print("Send Spot Request") ec2_client = boto3.client('ec2') res = ec2_client.request_spot_instances( ... ) request_id = res

发出即时请求并等待即时请求得到满足似乎是可行的

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

这就是我目前掌握的代码:

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

描述\u spot\u实例\u请求应给出spot创建的实例ID的名称


请参阅:

您是否尝试过描述现场实例请求?对于spot创建的实例ID?参考:是的,监督所有描述功能。通过这种方式,我还获得了ec2实例,并且能够解决上面代码中所有剩余的“TODO”。如果你把它写下来作为回答,我会接受的。