Skip to content

Commit 71ba0c1

Browse files
committed
Added S3 and CloudFront in AWS
1 parent 0f428a0 commit 71ba0c1

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

menu.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def awsConfigure():
3838

3939
def webserver():
4040

41-
key = input("Enter key name with .pem extension: ")
41+
key = input("\nEnter key name with .pem extension: ")
4242
address = out("echo %USERPROFILE%").rstrip("\n")
4343
key = r"{}\KeyPairs\{}".format(address, key)
4444
instance = input("Enter instance-id : ")
@@ -67,10 +67,47 @@ def webserver():
6767
error4 = os.system("ssh -i {} ec2-user@{} sudo systemctl status httpd".format(key, publicDns))
6868
elif choice == 'q' or choice == 'Q':
6969
break
70+
else:
71+
print("Invalid choice!!! Choose from 1-4 or Press Q to exit.\n")
7072
print("rc : {}:{}:{}:{}".format(error1,error2,error3,error4))
7173
return
7274

7375

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("\nEnter 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+
74111
def awsMenu():
75112
print('\n')
76113
error = os.system('aws --version')
@@ -97,11 +134,13 @@ def awsMenu():
97134
elif choice == '2':
98135
webserver()
99136
elif choice == '3':
100-
break
137+
s3()
101138
elif choice == '4':
102-
break
139+
cloudfront()
103140
elif choice == 'Q' or choice =='q':
104141
return
142+
else:
143+
print("Invalid choice!!! Choose from 1-4 or Press Q to exit.\n")
105144
return
106145

107146

0 commit comments

Comments
 (0)