EC2:等待直到新实例处于运行状态 [英] EC2: Waiting until a new instance is in running state

查看:43
本文介绍了EC2:等待直到新实例处于运行状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于存储的AMI创建一个新实例.

I would like to create a new instance based on my stored AMI.

我是通过以下代码实现的:

I achieve this by the following code:

RunInstancesRequest rir = new RunInstancesRequest(imageId,1, 1);
// Code for configuring the settings of the new instance
...
RunInstancesResult runResult = ec2.runInstances(rir);

但是,在实例启动并与Thread.currentThread().sleep(xxxx)命令分开运行之前,我找不到阻塞"/等待的等待.

However, I cannot find a wait to "block"/wait until the instance is up and running apart from Thread.currentThread().sleep(xxxx) command.

另一方面,StartInstancesResult和TerminateInstancesResult为您提供了一种访问实例状态并能够监视任何更改的方法.但是,一个全新实例的状态又如何呢?

On the other hand, StartInstancesResult and TerminateInstancesResult gives you a way to have access on the state of the instances and be able to monitor any changes. But, what about the state of a completely new instance?

推荐答案

等待EC2实例准备就绪是一种常见的模式.在Python库boto中,您还可以通过 sleep 调用解决此问题:

Waiting for the EC2 instance to get ready is a common pattern. In the Python library boto you also solve this with sleep calls:

   reservation = conn.run_instances([Instance configuration here])
   instance = reservation.instances[0]

   while instance.state != 'running':
       print '...instance is %s' % instance.state
       time.sleep(10)
       instance.update()

通过这种机制,您将能够在新实例出现时进行轮询.

With this mechanism you will be able to poll when your new instance will come up.

这篇关于EC2:等待直到新实例处于运行状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆