@@ -42,7 +42,7 @@ def launchInstance():
4242
4343 print ("Create Instance with instanceID : {}, type : t2.micro, key-name : {}, security-group : {} ?" .format (imageID , keyname , securityGroup ))
4444 create = input ("Enter Y to confirm : " )
45- if create == 'Y' :
45+ if create == 'Y' or create == 'y' :
4646 errorInstance = subprocess .call (
4747 "aws ec2 run-instances --image-id {} --count 1 --instance-type t2.micro --key-name {} --security-groups {} --profile {}" .format (imageID , keyname , securityGroup , profile ))
4848 if errorInstance == 0 :
@@ -168,19 +168,27 @@ def awsConfigure():
168168
169169def awsMenu ():
170170 print ('\n ' )
171- os .system ('aws --version' )
172-
171+ error = os .system ('aws --version' )
172+ print (error )
173+ if error != 0 :
174+ print ("No version of AWS CLI found. Would you like to install AWS CLIv2 ? (Press Y to confirm)" )
175+ install = input ("> " )
176+ if install == 'y' or install == 'Y' :
177+ subprocess .call ("msiexec /i https://awscli.amazonaws.com/AWSCLIV2.msi" )
178+ return
179+ else :
180+ return
173181 while True :
174182 if not loginAWS :
175183 awsConfigure ()
176184 else :
177185 print ("\n AWS MENU\
178186 \n --------" )
179- print ("\n 1. Launch instance \t 2. Show Key-Pairs \t 3. Delete Key-Pair\
180- \n 4. Show Security-Groups\t 5. Delete Security-Group\t 6. Add Inbound Rules\
181- \n 7. Show Instances \t 8. Start Instance \t 9. Stop Instance\
182- \n 10.AWS Configure \t 11.List Profiles \t \
183- \n \n Press Q to exit" )
187+ print ("\n 1. Launch instance \t 2. Show Key-Pairs \t 3. Delete Key-Pair\
188+ \n 4. Show Security-Groups \t 5. Delete Security-Group\t 6. Add Inbound Rules\
189+ \n 7. Show Instances \t 8. Start Instance \t 9. Stop Instance\
190+ \n 10.Terminate Instance \t 11.AWS Configure \t 12.List Profiles \
191+ \n \n Press Q to exit" )
184192 choice = input ("> " )
185193 if choice == '1' :
186194 launchInstance ()
@@ -189,17 +197,19 @@ def awsMenu():
189197 "aws ec2 describe-key-pairs --profile {}" .format (profile ))
190198 elif choice == '3' :
191199 keypair = input ("\n Enter name of key-pair to delete : " )
192- os .system (
200+ error = os .system (
193201 "aws ec2 delete-key-pair --key-name {} --profile {}" .format (keypair , profile ))
194- print ("Key-Pair : {} deleted." .format (keypair ))
202+ if error == 0 :
203+ print ("Key-Pair : {} deleted." .format (keypair ))
195204 elif choice == '4' :
196205 os .system (
197206 "aws ec2 describe-security-groups --profile {}" .format (profile ))
198207 elif choice == '5' :
199208 sg = input ("\n Enter name of security-group to delete : " )
200- os .system (
209+ error = os .system (
201210 "aws ec2 delete-security-group --group-name {} --profile {}" .format (sg , profile ))
202- print ("Security-Group : {} deleted." .format (sg ))
211+ if error == 0 :
212+ print ("Security-Group : {} deleted." .format (sg ))
203213 elif choice == '6' :
204214 inboundRules ()
205215 elif choice == '7' :
@@ -208,25 +218,32 @@ def awsMenu():
208218 instance_id = input ("\n Enter instance-id : " )
209219 error = subprocess .call ("aws ec2 start-instances --instance-ids {} \
210220 --profile {}" .format (instance_id , profile ))
211- if error == '0' :
221+ if error == 0 :
212222 print ("Instance started successfully." )
213223 print ("rc : {}" .format (error ))
214224 elif choice == '9' :
215225 instance_id = input ("\n Enter instance-id : " )
216226 error = subprocess .call ("aws ec2 stop-instances --instance-ids {} \
217227 --profile {}" .format (instance_id , profile ))
218- if error == '0' :
228+ if error == 0 :
219229 print ("Instance stopped successfully." )
220230 print ("rc : {}" .format (error ))
221231 elif choice == '10' :
222- awsConfigure ()
232+ instance_id = input ("\n Enter instance-id : " )
233+ error = subprocess .call ("aws ec2 terminate-instances --instance-ids {} \
234+ --profile {}" .format (instance_id , profile ))
235+ if error == 0 :
236+ print ("Instance termination processed. Instance will be deleted in some time." )
237+ print ("rc : {}" .format (error ))
223238 elif choice == '11' :
239+ awsConfigure ()
240+ elif choice == '12' :
224241 os .system ("aws configure list-profiles" )
225242 elif choice == 'Q' or choice == 'q' :
226243 print ("Exiting...\n " )
227244 break
228245 else :
229- print ("Invalid choice!!! Choose from 1-11 or Q to exit.\n " )
246+ print ("Invalid choice!!! Choose from 1-12 or Q to exit.\n " )
230247 return
231248
232249
0 commit comments