私はboto
PythonでEC2ワークフローの一部を自動化するために使用しています。
この問題は非常に奇妙です。スクリプトは単純な変数の割り当てでフリーズしているように見えますが、バックグラウンドで続行されています。最終的に、スクリプトはすべてを出力します。
iPythonでスクリプトを1行ずつ繰り返すと、問題は発生せず、フリーズしたり待機したりすることもありません(AWSで話すときに期待する以上のことはありません)。Pythonスクリプトとして実行すると、スクリプトが完了するまで出力がフリーズするようです。
スクリプト:
def deploy_web_db_ami(a_key, a_pri, db_vol_id, db_vol_zone, db_vol_mnt):
'''deploys a fresh instance for using as the web / db server.
'''
#Connect to the EC2
print "Connecting to AWS"
conn = EC2Connection(a_key, a_pri)
# get a ref to the image we want to install
print "Searching for desired AMI image"
image = conn.get_all_images(image_ids='ami-fd589594')
print "Spinning up instance. . ."
# Launch the image using our desired settings.
reservation = image[0].run(key_name='my_kp',
security_groups=['ssh'],
instance_type='t1.micro)
print("we get this far before output freezes")
ins = reservation.instances[0]
print "Waiting for instance to move from pending to running. ",
while (ins.state.lower() == u'pending'):
print ". ",
ins.update()
time.sleep(5)
time.sleep(5) # in case ssh is not up yet
print "Instance %s's state changed to: %s" (ins.id, ins.state)
if ins.state.lower() == u'running':
# instance is up and running
# Attach the db EBS volume
print "Attaching DB EBS volume."
conn.attach_volume(db_vol_id, ins.id, db_vol_mnt)
p_dns = ins.dns_name
else:
print "ERROR - INSTANCE NOT RUNNING.:: %s" % ins.state
print "All done!"
return (ins.id, p_dns)
def total_web_deploy():
deploy_web_db_ami('xxx', 'xxx', 'the id', 'the zone', '/mnt/sdf')
some_other_functions(). ..
コマンドラインからスクリプトを実行していますfab total_web_deploy
出力は次のようになります。
Connecting to AWS
Search for desired AMI image
Spinning up instance. . .
we get this far before output freezes
次に、残りのスクリプトが出力される前に、インスタンスとすべてが終了するのを待つ必要があります。しかし、それは明らかにバックグラウンドで機能していません。
Waiting for instance to move from pending to running. . . . . . . . . . . Instance i-95c389f6's state changed to: running
Attaching DB EBS volume.
All done!
何か案は?
編集私は質問を明確にしました。