J'utilise boto
en Python pour automatiser certains de mes flux de travail EC2.Figer le script Boto lors du déploiement et de la configuration des instances EC2
Le problème est très étrange - le script semble se bloquer sur une affectation d'une variable simple, mais il continue en arrière-plan. Finalement, le script imprime tout. Lorsque je répète le script ligne par ligne dans iPython, il n'y a pas de problèmes et pas de gel ou d'attente (au-delà de ce que vous attendez lorsque vous parlez de l'AWS). La sortie semble juste geler quand je l'exécute comme un script Python, jusqu'à ce que le script soit terminé.
Le script:
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(). ..
Je suis en cours d'exécution du script à partir de la ligne de commande en utilisant fab total_web_deploy
La sortie ressemblera à ceci:
Connecting to AWS
Search for desired AMI image
Spinning up instance. . .
we get this far before output freezes
Ensuite, nous allons devoir attendre pour l'instance et tout doit être terminé avant que le reste du script ne s'imprime. Cependant, cela fonctionne clairement en arrière-plan.
Waiting for instance to move from pending to running. . . . . . . . . . . Instance i-95c389f6's state changed to: running
Attaching DB EBS volume.
All done!
Des idées?
EDIT J'ai clarifié la question.
Eh oui, c'était le problème. . . Merci! – Edwardr