mercredi 25 mars 2015

Automating EC2 creation using Python

I'm trying to automate creating Windows images on EC2 using a Python script and Windows Task Scheduler. So far I have this as my working baseline code.



awsstring1 = 'aws ec2 create-image --instance-id i-49a0a7b3 --name "Node.Js.ServerTest " --output text --description "Node.Js.ServerTest" --no-reboot'
subprocess.call(awsstring1)


Now I want to attach a date and time to the description and name as the additional information. See below



datestring = time.strftime("%c")
awsstring1 = 'aws ec2 create-image --instance-id i-49a0a7b3 --name "Node.Js.ServerTest %s" --output text --description "Node.Js.ServerTest %s" --no-reboot' %(datestring, datestring))
subprocess.call(awsstring1)


Now the code runs with no errors but it doesn't create the image. Is it because of the way I created the awsstring1? If so, is there a work around to this?


Also, is there a way to obtain the output after running a subprocess.call command? For example I want to capture the output of



subprocess.call('ls -a')


Thanks!





Aucun commentaire:

Enregistrer un commentaire