amazon_cloud_service_3.py 1.4 KB

12345678910111213141516171819202122232425
  1. def upload_files(self, list_of_files):
  2. """upload_files on success of validation, this method uploads the give list of files to s3 bucket"""
  3. if self.__validation_result:
  4. self.count = 0 # local variable which tells count of files uploaded in S3 Buckets
  5. print(
  6. "Sample of file to be uploaded to S3 Buckets are \t {} ".format(
  7. list_of_files[:20]))
  8. for each_file in tqdm(list_of_files):
  9. try:
  10. self.__s3_resource = boto3.resource(service_name='s3',
  11. aws_access_key_id=self.__access_key,
  12. aws_secret_access_key=self.__secret_access_key,
  13. region_name=self.__region)
  14. self.__s3_resource.Bucket(self.__bucket).upload_file(
  15. Filename=each_file, Key=self.s3_file_name)
  16. # .upload_file from boto3 package uploads file to s3
  17. self.count += 1
  18. except Exception as e:
  19. print("Failed to upload file\n {}".format(each_file, e))
  20. else:
  21. print("please update the credentials to proceed further")
  22. print("Total file successfully uploaded:\t {}".format(self.count))
  23. return True