MCPcopy Create free account
hub / github.com/aws/aws-cli / S3Uploader

Class S3Uploader

awscli/customizations/s3uploader.py:54–216  ·  view source on GitHub ↗

Class to upload objects to S3 bucket that use versioning. If bucket does not already use versioning, this class will turn on versioning.

Source from the content-addressed store, hash-verified

52
53
54class S3Uploader:
55 """
56 Class to upload objects to S3 bucket that use versioning. If bucket
57 does not already use versioning, this class will turn on versioning.
58 """
59
60 @property
61 def artifact_metadata(self):
62 """
63 Metadata to attach to the object(s) uploaded by the uploader.
64 """
65 return self._artifact_metadata
66
67 @artifact_metadata.setter
68 def artifact_metadata(self, val):
69 if val is not None and not isinstance(val, collections_abc.Mapping):
70 raise TypeError("Artifact metadata should be in dict type")
71 self._artifact_metadata = val
72
73 def __init__(
74 self,
75 s3_client,
76 bucket_name,
77 prefix=None,
78 kms_key_id=None,
79 force_upload=False,
80 transfer_manager=None,
81 ):
82 self.bucket_name = bucket_name
83 self.prefix = prefix
84 self.kms_key_id = kms_key_id or None
85 self.force_upload = force_upload
86 self.s3 = s3_client
87
88 self.transfer_manager = transfer_manager
89 if not transfer_manager:
90 self.transfer_manager = TransferManager(self.s3)
91
92 self._artifact_metadata = None
93
94 def upload(self, file_name, remote_path):
95 """
96 Uploads given file to S3
97 :param file_name: Path to the file that will be uploaded
98 :param remote_path: be uploaded
99 :return: VersionId of the latest upload
100 """
101
102 if self.prefix and len(self.prefix) > 0:
103 remote_path = f"{self.prefix}/{remote_path}"
104
105 # Check if a file with same data exists
106 if not self.force_upload and self.file_exists(remote_path):
107 LOG.debug(
108 f"File with same data already exists at {remote_path}. "
109 "Skipping upload"
110 )
111 return self.make_url(remote_path)

Calls

no outgoing calls