擅长:python、mysql、java
<p>在创建实例之前,无法创建标记。尽管这个函数被称为create_instance,但它真正做的是保留和实例。然后,该实例可以启动,也可以不启动。(通常是,但有时…)</p>
<p>因此,在启动标记之前,不能添加该标记。如果没有投票就无法判断它是否已经启动。就像这样:</p>
<pre><code>reservation = conn.run_instances( ... )
# NOTE: this isn't ideal, and assumes you're reserving one instance. Use a for loop, ideally.
instance = reservation.instances[0]
# Check up on its status every so often
status = instance.update()
while status == 'pending':
time.sleep(10)
status = instance.update()
if status == 'running':
instance.add_tag("Name","{{INSERT NAME}}")
else:
print('Instance status: ' + status)
return None
# Now that the status is running, it's not yet launched. The only way to tell if it's fully up is to try to SSH in.
if status == "running":
retry = True
while retry:
try:
# SSH into the box here. I personally use fabric
retry = False
except:
time.sleep(10)
# If we've reached this point, the instance is up and running, and we can SSH and do as we will with it. Or, there never was an instance to begin with.
</code></pre>