@@ -38,7 +38,7 @@ def awsConfigure():
38
38
39
39
def webserver ():
40
40
41
- key = input ("Enter key name with .pem extension: " )
41
+ key = input ("\n Enter key name with .pem extension: " )
42
42
address = out ("echo %USERPROFILE%" ).rstrip ("\n " )
43
43
key = r"{}\KeyPairs\{}" .format (address , key )
44
44
instance = input ("Enter instance-id : " )
@@ -67,10 +67,47 @@ def webserver():
67
67
error4 = os .system ("ssh -i {} ec2-user@{} sudo systemctl status httpd" .format (key , publicDns ))
68
68
elif choice == 'q' or choice == 'Q' :
69
69
break
70
+ else :
71
+ print ("Invalid choice!!! Choose from 1-4 or Press Q to exit.\n " )
70
72
print ("rc : {}:{}:{}:{}" .format (error1 ,error2 ,error3 ,error4 ))
71
73
return
72
74
73
75
76
+ def s3 ():
77
+ while True :
78
+ error1 , error2 = 0 ,0
79
+ print ("\n 1. Create S3 Bucket\
80
+ \n 2. Upload to S3 Bucket\
81
+ \n \n Press Q to quit" )
82
+ choice = input ("> " )
83
+ if choice == '1' :
84
+ bucket = input ("Enter bucket name : " )
85
+ error1 = os .system ("aws s3api create-bucket --bucket {} --region ap-south-1 \
86
+ --create-bucket-configuration LocationConstraint=ap-south-1 --no-verify-ssl" .format (bucket ))
87
+ if error1 == 0 :
88
+ print ("Bucket '{}' created successfully." .format (bucket ))
89
+ elif choice == '2' :
90
+ file = input ("Enter absolute path of file you wish to upload : " )
91
+ bucket = input ("Enter bucket name : " )
92
+ error2 = os .system ("aws s3 cp {} s3://{}/ --acl public-read-write" .format (file , bucket ))
93
+ if error2 == 0 :
94
+ print ("File '{}' added to Bucket '{}' successfully." .format (file , bucket ))
95
+ elif choice == 'q' or choice == 'Q' :
96
+ break
97
+ else :
98
+ print ("Invalid choice!!! Choose 1 or 2 or Press Q to exit.\n " )
99
+ return
100
+
101
+
102
+ def cloudfront ():
103
+ bucket = input ("\n Enter bucket name : " )
104
+ print ("Setting up CloudFront ..." )
105
+ error = os .system (
106
+ "aws cloudfront create-distribution --origin-domain-name {}.s3.amazon.com" .format (bucket ))
107
+ if error == 0 :
108
+ print ("CloudFront distribution created successfully." )
109
+ return
110
+
74
111
def awsMenu ():
75
112
print ('\n ' )
76
113
error = os .system ('aws --version' )
@@ -97,11 +134,13 @@ def awsMenu():
97
134
elif choice == '2' :
98
135
webserver ()
99
136
elif choice == '3' :
100
- break
137
+ s3 ()
101
138
elif choice == '4' :
102
- break
139
+ cloudfront ()
103
140
elif choice == 'Q' or choice == 'q' :
104
141
return
142
+ else :
143
+ print ("Invalid choice!!! Choose from 1-4 or Press Q to exit.\n " )
105
144
return
106
145
107
146
0 commit comments