I am not very familiar with coding (...) I am trying to set up a script that validates the connection to an S3 endpoint. The idea is, If the connection is established ( with HTTP return code 200 ), a message will printed telling "Connection is established", and if any other code that 20x ( 40x for instance ), the error message will be written in log file:
def validation_inputs(self):
self.credChamploginS3 = self.ChamploginS3.get()
self.credChampsecretpasseS3 = self.ChampsecretpasseS3.get()
self.credChampsendpointS3 = self.ChampsendpointS3.get()
#print(credChamploginS3,credChampsecretpasseS3,credChampsendpointS3)
s3conn = boto.connect_s3(
aws_access_key_id = self.credChamploginS3,
debug=2,
aws_secret_access_key = self.credChampsecretpasseS3,
host = self.credChampsendpointS3,is_secure=False,
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)
now = datetime.datetime.now()
if s3conn is None:
print"log : No S3 Connection, creating a new one. BAD INPUTS"
print "time :" + now.strftime("%Y-%m-%d %H:%M")
else:
print"log : S3 Connection, validated."
print "Current date and time using strftime:"
print now.strftime("%Y-%m-%d %H:%M")
#self.bucket = self.conn.get_all_buckets()
#or key in buckets:
#print key.name
listsbuckets = s3conn.get_all_buckets()
for bucket in listsbuckets:
print "{name}\t{created}".format(name = bucket.name,created = bucket.creation_date)
#buckets = s3conn.get_all_buckets()
#for key in buckets:
# print key.name
Aucun commentaire:
Enregistrer un commentaire